@abdulbazith I'll say read this https://docs.laravel-excel.com/3.1/imports/collection.html and in collections, you shud write custom logic to create records in your DB. Hope it'll help you. Cheers!
Call to undefined method Maatwebsite\Excel\Excel::load() laravel uploading with excel data into table
guys working with online exam project. i need to add students data bulk.
so i planned to using maatwebsite/excel
i saw composer show in my gitbash it showed like below.
maatwebsite/excel 3.1.19 Supercharged Excel exports...
but in my composer.json
"require": {
"php": "^7.2",
"barryvdh/laravel-dompdf": "^0.8.6",
"fideloper/proxy": "^4.0",
"filp/whoops": "^2.7",
"intervention/image": "^2.5",
"laravel/framework": "^6.2",
"laravel/tinker": "^2.0",
"realrashid/sweet-alert": "^3.1",
"spatie/laravel-permission": "^3.11",
"uxweb/sweet-alert": "^2.0",
"yajra/laravel-datatables-buttons": "^4.0",
"yajra/laravel-datatables-editor": "^1.19",
"yajra/laravel-datatables-fractal": "^1.5",
"yajra/laravel-datatables-html": "^4.22",
"yajra/laravel-datatables-oracle": "^9.8"
},
My first confusion is whether that package is there are not in my project?
next i tried to upload excel data this is my coding
$this->validate($request, [
'student_excel_file' => 'required|mimes:xls,xlsx'
]);
$path = $request->file('student_excel_file')->getRealPath();
$data = Excel::load($path)->get();
dump( $data);
this shows error
Call to undefined method Maatwebsite\Excel\Excel::load()
when i google most of them said in maatwebsite version 3 and above load is depreciated. so most of them said to switch back to version 2. iam unable to do.
i ran composer remove maatwesbite/excel. but i cant see it in composer.json. but still the package exist. what should i do??
let me say my process. i need to get student_name, student_username, student_password from form and it will be stored in StudentRegistration table and then it is stored in user table with userprofile as polymorph table
this is my coding
$data = $request->all();
foreach ($data['student_name'] as $i => $name) {
$addstudent = new StudentRegistration([
'login_user_id' => auth()->id(),
'school_id' => $request->school_id,
'class_id' => $request->class_id,
'section_id' => $request->section_id,
'stud_name' => $name,
'stud_status' => "active",
]);
$addstudent->save();
$addstudent->user()->create(
['name' => $name,
'username' => $data['username'][$i],
'user_type' => "student",
'password' => $data['password'][$i],
'status' => "active"
]);
}
alert()->success('Student Added Successfully');
Now i need to do the same process from excel sheet.. how can i do that
i referred this link for uploading using excel sheet: https://www.webslesson.info/2019/02/import-excel-file-in-laravel.html
kindly some one suggest please..
Please or to participate in this conversation.