Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 应用过滤器时的Laravel路由错误_Php_Laravel - Fatal编程技术网

Php 应用过滤器时的Laravel路由错误

Php 应用过滤器时的Laravel路由错误,php,laravel,Php,Laravel,我正在尝试将身份验证添加到我的Laravel应用程序中。用户可以很好地登录,但我希望确保任何进入页面的人都已登录-我不希望有人在应用程序中为页面添加书签,然后在未确保他们已登录的情况下进入页面 因此,我一直在研究过滤器。我一定没有正确地实现它,因为我得到以下错误call\u user\u func\u array()期望参数1是有效的回调,当我转到添加筛选器的其中一个路由或链接到筛选路由的任何页面时,没有给出数组或字符串 Routes.php Route::get( '/admin/login'

我正在尝试将身份验证添加到我的Laravel应用程序中。用户可以很好地登录,但我希望确保任何进入页面的人都已登录-我不希望有人在应用程序中为页面添加书签,然后在未确保他们已登录的情况下进入页面

因此,我一直在研究过滤器。我一定没有正确地实现它,因为我得到以下错误
call\u user\u func\u array()期望参数1是有效的回调,当我转到添加筛选器的其中一个路由或链接到筛选路由的任何页面时,没有给出数组或字符串

Routes.php

Route::get( '/admin/login',          'UserController@getAdminLoginForm');
Route::get( '/admin/races',          array('before' => 'auth', 'RaceController@getAllRacesView'));
Route::get( '/admin/geographies',    array('before' => 'auth', 'GeographyController@getLocalGeographiesView'));
Route::get( '/admin/candidates',     array('before' => 'auth', 'CandidateController@getAllCandidatesView'));
Filters.php

Route::filter('auth', function() {
    if (Auth::guest()) return Redirect::guest('/admin/login');
});

在使用过滤器之前,我已经准备好了这些页面,那么我在实现这一点时还缺少什么呢?

以下是文档中关于向控制器操作添加过滤器的说明:

路由::get('user',array('before'=>'old','uses'=>'UserController@showProfile'));

简而言之,您缺少数组键
uses
。试着这样做:

Route::get('/admin/races',    array('before' => 'auth', uses => 'RaceController@getAllRacesView'));

天哪,你说的对。我一定是在备份东西的时候把那部分拆了。我最初让它工作了5分钟,然后我解开了一些东西,它停止了工作。一定是这样。非常感谢你!!