我想在AppserviceProvider中訪問Authenticated user id它的工作正常,當我在應用程序中意味着一旦登錄其工作正常,但是當我註銷它給出錯誤而不是去到登錄頁面錯誤試圖獲取非對象的屬性(laravel 5.3)
試圖讓非對象
這是我寫的引導方法Appserviceprovider的代碼的性能。
public function boot()
{
view()->composer('*', function($view){
$view->with('user', Auth::user());
$counter = DB::table('notifications')->where('notifications.userid', Auth::user()->id)->count();
View::share('counter', $counter);
});
它會給我上面的查詢where子句時出錯,當我註銷。其原因後註銷其無法得到auth用戶ID .. 請幫助我如何解決或如何做到這一點的最好的方式,如果任何
當你註銷'Auth :: user() - > id'時,問題出在這裏'Auth :: user()'是空的 – Beginner