I get an error while exporting. The way of use is as follows. Can you help me ?
Error: InvalidArgumentException: The filename and the fallback cannot contain the "/" and "\" characters.
Code:
$excel_database_product = DB::table('product_excel')->get()->toArray();
$result= new ExcelArrayExport($excel_database_product );
Excel::download($result, storage_path("new_product.xlsx"));
class ExcelArrayExport implements FromArray
{
protected $array;
public function __construct(array $array)
{
$this->array = $array;
}
public function array(): array
{
return json_decode( json_encode($this->array), true);
}
}
Excel::download($result, storage_path("new_product.xlsx")); should be Excel::download($result, 'new_product.xlsx'); Download expects a filename not a filepath.
So how can I specify the file path?
Why do you want to specify the file path for a download?
I want to replace the excel file in a folder
You need ::store not ::download then
Thanks for your help :)
Most helpful comment
Excel::download($result, storage_path("new_product.xlsx"));should beExcel::download($result, 'new_product.xlsx');Download expects a filename not a filepath.