I'm trying to Import an excel file and save the info into the database table. Right now I'm getting an error
The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE.
All the tutorials I saw didn't get this error and I'm doing it the same way, I don't know what the issue is. I'm using this package "maatwebsite/excel": "~2.1.3"
.
This is my vue
<el-form :action="'impteachers/import'" method="post" enctype="multipart/form-data">
<el-input type="file" name="file"/>
<el-input type="submit" value="upload"/>
</el-form>
This is the controller
public function import(Request $request)
{
$request->validate([
'file' => 'required|mimes:xls,xlsx'
]);
$path = $request->file('file')->getRealPath();
$data = Excel::load($path)->get();
if ($data->count()) {
foreach ($data as $key => $value){
$arr[] = [
'NOMBRE' => $value->name,
'CEDULA' => $value->card,
'CARNET' => $value->scard,
'TIPO-USUARIO' => $value->user_type_id,
'CORREO' => $value->email,
'PASSWORD' => $value->password,
];
}
if (!empty($arr)) {
User::insert($arr);
}
}
return redirect('/imports');
}
These are the routes in web.php
Route::resource('impteachers', 'ImportTeacherController');
Route::post('impteachers/import', 'ImportTeacherController@import');
What am I doing wrong?