当我使用这样的路线时,test
路线工作正常
路线: -
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::get('user/test','UserController@test'); // is working
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'USerController@planed']);
.
.
.
.
但是当我想像下面那样使用它时,它会显示一个空白页面:
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController@planed']);
Route::get('user/test','UserController@test'); // is not working
.
.
.
.
我的错误是什么?
答案 0 :(得分:1)
因为
拦截了对测试的调用Route::resource('user', 'UserController');
因为如果您使用
检查控制台中的路线$> php artisan route:list
你会看到它包含
GET|HEAD | user/{user}
然后是你的第一条路线
Route::get('user/test','UserController@test'); // is not working
永远不会到达。试着把它放在另一条线之前。
答案 1 :(得分:1)
我在命名路由检查时遇到了问题This
试试这个
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed','UserController@planed'])->name('user.planed');
Route::get('user/test','UserController@test'); // is not working
只需替换
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController@planed']);
用
Route::get('user/planed','UserController@planed'])->name('user.planed');