php - 使用输入表单查看 Laravel 路由

标签 php forms laravel routes

使用 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', ' 之后有 Route::get('lectures/{lecture}', 'LecturesController@show'); LecturesController@create');。 Laravel 将匹配第一条路线,然后停止,以便您实际上访问 Route::get('lectures/{lecture}', 'LecturesController@show'); 并在您的 show 方法中 $lecture === '创建'

关于php - 使用输入表单查看 Laravel 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40476745/

相关文章:

php - mysql 将多条数据插入单列或多行

javascript - 提交按钮同时使用两种方法,而不是一种方法,我该如何解决这个问题?

java - Spring MVC 窗体 :options tag not wiring into my objects Id?

PHP:在 MySQL Workbench 6.3 中使用 HTML 表单写入数据库

php - 拉维尔 5.3 : Best way to retrieve data between dates and group them in weeks?

php - 无法在 laravel 中创建表

laravel - 验证 POST 请求 Laravel?

php - 如何加速 codeigniter/php 分页,sql 查询

php - 在php中获取当前域+目录

php - Eloquent 查询的条件