I'm using Laravel 5.8 and I tried creating a custom command like this:
php artisan make:command app exportappresults
And the Command goes like this:
protected $signature = 'app:exportappresults';
protected $description = 'Export App Exam Result Into Excel';
public function __construct()
{
parent::__construct();
}
public function handle()
{
return Excel::download(new TavanmandAppUserExamExport,'userexamlist.xlsx');
}
So as you can see I have used Laravel Excel and tried exporting data into Excel file.
Note that this code works fine in the Controller and can properly export an Excel file.
But now I don't know where does the exported excel file from the DB goes when I use the Console Command.
So if you know, please let me know...
Thanks.
CodePudding user response:
Excel::download
is used in HTTP controllers, to pass exported data to HTTP response. If you need to store file on disk, use Excel::store
instead:
public function handle()
{
Excel::store(new TavanmandAppUserExamExport, 'userexamlist.xlsx');
}
File will be stored in default storage (disk), configured in laravel's config/filesystems.php
, by default it's ./storage/app
.
Also you may specify another disk as third argument of Excel::store
method, see Storing exports on disk