I have a function which is converting my blade view into Excel format and downloading it. Now I want to save it in a specified location, i.e: public/uploads/release Here is my controller:
public function export_release()
{
return Excel::download(new ReleaseExportView(), 'release.xlsx');
}
This function downloads the excel file downloads folder. I want to save it in the location: public/uploads/release
Here is my route:
Route::Get('outbounds/export_release' ,'outboundController@export_release')->name('outbounds.export_release');
You can use the store
method to store the file in the filesystem.
From the docs:
Exports can easily be stored on any filesystem that Laravel supports.
Default disk
public function storeExcel()
{
// Store on default disk
Excel::store(new InvoicesExport(2018), 'invoices.xlsx');
}
Custom disk
public function storeExcel()
{
// Store on a different disk (e.g. s3)
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3');
// Store on a different disk with a defined writer type.
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', Excel::XLSX);
}
Now ideally you would store the file in storage/app/public/uploads/release
and create a symlink from public/storage/
to storage/app/public
as explained here.
But if you really want to store it in public/uploads/release
you could create new custom disk in config/filesystems.php
. Something like:
'real_public' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
Then you could use the custom disk to store the file:
public function export_release()
{
Excel::store(new ReleaseExportView(), 'uploads/release/release.xlsx', 'real_public');
}
You can create a new storage disc in config/filesystems.php:
'excel_uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads/release',
],
And store files like this:
Storage::disk('excel_uploads')->put($path, $file_content)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With