这是我的路线:
Route::group(array('before' => 'auth'), function() {
Route::resource('restaurants', 'RestaurantsController');
});
我希望restaurants.create
对来宾用户可用。
这可能吗?
就像这样声明Route Group
外的路由:
Route::resource('restaurants', 'RestaurantsController');
而不是:
Route::group(array('before' => 'auth'), function() {
Route::resource('restaurants', 'RestaurantsController');
});
然后在RestaurantsController
控制器中添加before
过滤器在__construct
方法中,像这样:
public function __construct()
{
parent::__construct(); // If BaseController has a __construct method
$this->beforeFilter('auth', array('except' => array('create')));
}
所以所有的方法将auth
作为before
过滤器,但没有create
方法。如果你需要添加另一个before
过滤器,那么你可以在第一个过滤器之后添加另一个,像这样:
public function __construct()
{
parent::__construct(); // If BaseController has a __construct method
// Add auth as before filter for all methods but not for create
$this->beforeFilter('auth', array('except' => array('create')));
// Only for create method
$this->beforeFilter('anotherFilter', array('only' => array('create')));
}
我相信您正在寻找guest
过滤器,默认情况下应该包含它。
所以把这行改成:
Route::group(array('before' => 'auth'), function() {
:
Route::group(array('before' => 'guest'), function() {