Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel5中间件中给出auth条件_Php_Laravel_Laravel 5.4 - Fatal编程技术网

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()) {