Php Laravel 5.4函数索引尝试使用函数显示
我有一条路线:Php Laravel 5.4函数索引尝试使用函数显示,php,laravel,laravel-5,routes,Php,Laravel,Laravel 5,Routes,我有一条路线: Route::resource('admin/question', 'QuestionsController'); 和函数索引: public function index() { return "Hello"; } 但当我尝试使用索引时,Laravel返回了错误: 方法[show]不存在 我正在使用链接: http://localhost:8012/siwz/siwz/public/admin/question 服务器是WampServer程序。 我只能在更改路由
Route::resource('admin/question', 'QuestionsController');
和函数索引
:
public function index() {
return "Hello";
}
但当我尝试使用索引时,Laravel返回了错误:
方法[show]不存在
我正在使用链接:
http://localhost:8012/siwz/siwz/public/admin/question
服务器是WampServer程序。
我只能在更改路由文件时使用索引功能:
Route::get('admin/question/index', 'QuestionsController@index');
Route::resource('admin/question', 'QuestionsController');
在Laravel 5.3版中,我不必这样做,只需使用:
Route::resource('.../...', '...Controller');
实际上,URL将指向正确的函数<代码>管理员/问题应转到
索引
admin/question/{question}
是指向show
的路径
在这里查看并检查Laravel如何创建资源路由:
因为您没有提供完整的路线。我猜您访问的链接将连接到错误的控制器。你应该检查路线的顺序。也许你在路上碰到了这样的东西
Route::resource('admin','AdminController');
并且AdminController没有方法show()。这就是为什么拉威尔会返回那个错误
这是你能做的
- 注释掉除您正在访问的路由之外的其他路由
- 尝试重新排列受影响的路由。也许拉威尔对你的路线感到困惑
route::resource('admin/question','QuestionsController@index');代码>@VincentDecaux注册资源路由时指定方法名称是不正确的。不过,您可以做的是这样的Route::resource('question','QuestionController',['only'=>['index']])代码>