【发布时间】:2017-01-10 16:46:54
【问题描述】:
我正在尝试访问 AppserviceProvider 中经过身份验证的用户 ID,当我在应用程序中时它工作正常意味着一旦登录后它工作正常,但是当我注销时它给出错误并且不转到登录页面
试图获取非对象的属性
这是我用boot方法编写的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 子句中出现错误。这是因为注销后无法获取身份验证用户ID .. 请帮助我如何修复它或如何以最好的方式完成它(如果有的话)
【问题讨论】:
-
问题是这个
Auth::user()->id注销时Auth::user()是空的