使用 Laravel 5.3 我想要一个路由,该路由指向带有表单的 View 来创建新对象
我有这些路线
//to show all lectures
Route::get('lectures', 'LecturesController@index');
//to show specific lecture
Route::get('lectures/{lecture}', 'LecturesController@show');
//to display form to create a new Lecture
Route::get('lectures/create', 'LecturesController@create');
//to handle process of creating a new lecture
Route::post('lectures/create','LecturesController@store');
除应显示添加新讲座表格的路线外的所有工作均已找到。
public function create(){
return view('lectures.create');
}
它甚至没有到达 Controller ,因为当我转到地址“localhost/lectures/create”时,我得到了这两个异常:
ModelNotFoundException in Builder.php line 311:
No query results for model [App\Lecture].
NotFoundHttpException in Handler.php line 113:
No query results for model [App\Lecture].
我不知道为什么索引、显示和存储方法有效时它不起作用......
最佳答案
您需要在 Route::get('lectures/create', ' 之后有
。 Laravel 将匹配第一条路线,然后停止,以便您实际上访问 Route::get('lectures/{lecture}', 'LecturesController@show');
LecturesController@create');Route::get('lectures/{lecture}', 'LecturesController@show');
并在您的 show 方法中 $lecture === '创建'
关于php - 使用输入表单查看 Laravel 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40476745/