So I want to send a email in a particular time, when my command runs and with that email, i want to send an excel file with that email,i also have some data which i want to append in the excel file, i have used Excel::download() method but it creates the excel file in this path "storage/framework/laravel-excel",with the name like "laravel-excel-9ssyjrYnrNNOBU2wfi5eaGtXsRySkj4X" which i don't want, i want to store that excel file somewhere else in the storage folder and then retrieve it and send it with the email.
As of Now I have deleted all the files from the path "storage/framework/laravel-excel/" first and then created the new excel file which will store in the path which is mentioned in previous line , and then fetch the new file with the email and send it. But this approach is not looking good or code reviewer will definitely dissappointed by this code. Is there any better solution to this , i already tried store method but it doesn't give me result
Public function build(){
$directoryPath = storage_path('framework/laravel-excel/');
$files = File::glob("{$directoryPath}*.xlsx");
if($files){
File::delete($files);
}
Excel::download(new SellerPayoutExport([$this->record]) , 'SellerPayout'. '.'. 'xlsx');
$latestFile = reset($files);
return $this->from(core()->getSenderEmailDetails()['email'], core()>getSenderEmailDetails() ['name'])
->to('[email protected]')
->subject(trans('customshop::app.mail.seller-payout.subject'))
->view('customshop::emails.sales.seller-payouts')
->attach($latestFile, [
'as' => 'seller_payouts.xlsx',
'mime' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
);
}