方法AppHttpControllersScheduleController::store不存在



我试图导入文件excel(xlsx)数据库使用Maatwebsite,但得到了这个错误。在我的基础存储库中有函数存储。当我将函数存储添加到ScheduleController时,它运行并返回schedule.index,但它不导入我的excel文件。请帮帮我

enter code here
public function importSchedules(Request $request)
{
Excel::import(new ScheduleImport, request()->file('file')->store('files'));
return redirect()->route('schedule.index')->with('success');
}
<div class="form-group">
<form method="post" action="/schedule" enctype="multipart/form-data">
@csrf
<input type="file" name="file">
<button type="submit" class="btn btn-primary">add</button>
</form>
</div>
Route::post('/schedule', 'ScheduleController@importSchedules');

您可能还创建了一个资源路由。或者在你的web文件中一定有另一个路由在这个路由之上,所以这个请求可能会被那个路由拦截。首先,确定这一点。如果有资源路由,您可以在控制器上添加store方法,也可以在路由上添加except,如下所示https://laravel.com/docs/9.x/controllers#restful-partial-resource-routes

或者,您可以将此路由的名称更改为:

Route::post('/import-schedules', 'ScheduleController@importSchedules')->name('importSchedules');

而在表单中你必须改为:

<form method="post" action="{{route('importSchedules')}}" enctype="multipart/form-data">

最新更新