我已经在官方文档中看到了这个:
保护路线
Route::get('profile', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
但我不知道如何在我的情况下应用它。
这是我的routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('index', function()
{
return View::make('index');
});
Route::get('restaurants/admins/{id}', 'RestaurantsController@admins');
Route::resource('restaurants', 'RestaurantsController');
Route::post('admins/login', array('uses' => 'AdminsController@login', 'as' => 'admins.login'));
Route::post('admins/changePicutre', array('uses' => 'AdminsController@changePicture', 'as' => 'admins.changePicture'));
Route::resource('admins', 'AdminsController');
Route::resource('waitingtimes', 'WaitingtimesController');
Route::post('restaurants/changePicture', array('uses' => 'RestaurantsController@changePicture', 'as' => 'restaurants.changePicture'));
Route::get('login', function(){
return View::make('admins.login');
});
我需要所有路由仅适用于loing
路由以外的经过身份验证的用户。
答案 0 :(得分:3)
使用Route::group()
以使用过滤器保护组内的所有路由,如下所示:
// All routes in the group are protected, only authed user are allowed to access them
Route::group(array('before' => 'auth'), function() {
Route::get('restaurants/admins/{id}', 'RestaurantsController@admins');
});
// Login, all users allowed
Route::get('login', function(){
return View::make('admins.login');
});
答案 1 :(得分:1)
Route::get('yourRoutes', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
Route::get('routes',array('before'=>'auth','as'=>'namedRoute','uses'=>'controller');