I created my code following following few tutorials. As my csv file has more than 300k rows I need to upload it as chunks, but unable to figure out how to do that.
Mainly followed this tutorial and several others including some laracast discussions https://itsolutionstuff.com/post/import-and-export-csv-file-in-laravel-58example.html
My Controller import function
public function import()
{
Excel::import(new ReportImport, request()->file('file'));
return view('dashboard');
}
My ReportImport File
namespace App\Imports;
use App\Report;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class ReportImport implements ToModel, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new Report([
'district' => $row['district'],
'age' => $row['age'],
'email' => $row['email'],
'name' => $row['name'],
]);
}
}
Illuminate \ Http \ Exceptions \ PostTooLargeException No message