我創建了自己的過濾器和視圖作曲家。這裏首先是代碼:Laravel 4過濾器和視圖作曲家
我的管理員過濾器:
Route::filter('admin', function()
{
if (Auth::check())
{
$roles = Auth::user()->role;
if ($roles == '5')
{
return Redirect::to('news/index')->with('roles', $roles);
}
}
else
{
return View::make('errors.401');
}
});
和我的View Composer(它在global.php):
// View composer
View::composer(array('common.menu_addition','common.base_errors'), function($view)
{
if (Auth::check())
{
$roles = Auth::user()->type;
if ($roles == '5')
{
$view->with('roles', $roles);
}
else
{
$view;
}
}
else
{
return Redirect::to('news/index');
}
});
所以這是行不通的。我想用我的管理員帳戶訪問一些頁面(角色等於5,數據庫中的'角色'列)。我在我的路線中創建了一個組,但是當我嘗試訪問一個頁面時,它會將我重定向到我的新聞/索引頁面。
我該如何設置它使任何頁面需要管理角色可見?
我還使用Jeffrey Way的發生器製作腳手架,如果有幫助的話。