Php 如何在laravel5中间件中给出auth条件
我有一个用Php 如何在laravel5中间件中给出auth条件,php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,我有一个用前端调用的中间件,该中间件的用法是显示我用它创建的菜单 但是我上面用auth编写的脚本不起作用。我得到这个错误 在null上调用成员函数isDeveloper() 这是我的用户模型 class User extends Authenticatable { use Notifiable; protected $fillable = [ 'name', 'email', 'password','type','subscribestatus','userco
前端调用的中间件,该中间件的用法是显示我用它创建的菜单
但是我上面用auth
编写的脚本不起作用。我得到这个错误
在null上调用成员函数isDeveloper()
这是我的用户模型
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password','type','subscribestatus','usercode'
];
protected $hidden = [
'password', 'remember_token',
];
public function isDeveloper()
{
return ($this->type == 'TP001');
}
}
如何修复错误?对不起,我的英语不好 在尝试调用函数之前,请确保用户已登录:
if (auth()->check() && auth()->user()->isDeveloper()) {
已经这么做了。但是,我在两个不同用户类型的浏览器中登录。他们两人都没有在菜单上显示condition@YVS1102如果错误不再发生,那么问题就出在其他方面了。可能是isDeveloper()
标志工作不正常。
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password','type','subscribestatus','usercode'
];
protected $hidden = [
'password', 'remember_token',
];
public function isDeveloper()
{
return ($this->type == 'TP001');
}
}
if (auth()->check() && auth()->user()->isDeveloper()) {