Home » Php » php – Laravel Excel Storing Under a directory inside Disks

php – Laravel Excel Storing Under a directory inside Disks

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am using Laravel Excel to Create Excels Files, I have multiple Excels for one Projects to be download say 10 Excel Sheets which runs on Queue which I have to zip it after storing all the files.

I have a disk configures in filesystems.php like so

'exports' => [
   'driver' => 'local',
   'root' => storage_path('app/public/poc'),
]

Now when I store the Excels I create a folder under the disk like organizationsName and then I want to store inside that folder inside to the disk directly.

Currently my code is like so

$organization = $project->first()->load('organization')->organization->name;
Storage::disk('exports')->makeDirectory($organization);
foreach ($project as $p)
{
   Excel::store(new DownloadProjects($project, $p->id), $poc->title.' Project Data.xlsx', 'exports');
}

How can I store the Files inside the Disk’s Directory?

How to&Answers:
foreach ($project as $p)
{
    Excel::store(new DownloadProjects($project, $p->id), /<path to folder from export disk>/$poc->title.' Project Data.xlsx', 'exports');
}

Change your excel store second parameter as the above one. Just mention the path to the required space from the mentioned disk.