我有問題。我做了一個函數,說如果'type'(我的數據庫中的一列)等於五,它將顯示其他人無法查看的按鈕。問題是當我註銷或登錄到沒有類型等於五的用戶時,它顯示一個錯誤。我怎麼能在一個if函數中做到這一點?我嘗試了各種各樣的東西,但它總是顯示錯誤。這是我的公共職能:Laravel 4公共職能
public function get_dash() {
$roles = Auth::user()->type;
if ($roles == '5')
{
return View::make('admin.dash')->with('roles', $roles);
} else {
return Redirect::to('news/index')->with('danger', 'You either have insufficient permissions to access this page or your user credentials are not refreshed.');
}
}
所以我基本上想它,如果沒有類型等於五個賬戶,或當我退出這將可以正常加載(只是return View::make('news/index');
)。
顯示什麼錯誤? –
@Antonio Carlos Ribeiro 它說錯誤在$ roles = Auth :: user() - > type; ,當我將它作爲客人查看時,錯誤:'嘗試獲取非對象的屬性' – dinomuharemagic