Thanks @tomi, for your reply. In my case, I am just importing the csv file. Seems useful when exporting xls, am I wrong?
Sep 1, 2016
7
Level 1
Laravel Excel: save filename into database
Hi. Using maatwebsite plugin to import csv file data into database. It is a stupid question, but how can I save also the filename?
Here is what I am using:
$file = Input::file('csv_file');
Excel::filter('chunk')
->load($file->getRealPath())
->chunk(250, function($results) {
foreach($results as $row)
{
$sales = Sale::create([
'company_code' => $row->xxxx,
'sale_year_month' => $row->xxxx,
'sale_date' => $row->xxxx
]);
}
});
return Redirect::to('/');
I tried to use this after the file upload:
$sales->csv_file = $destinationPath.'/'.$name;
$sales>save();
But it created a new extra record with just the filename path.
Thank you.
Please or to participate in this conversation.