bossby
1570
2
Laravel

Condition in laravel 5 Middleware always false

Posted 2 years ago by bossby

I'm trying to give condition in my Middleware. Here is my script

        if (auth()->check() && auth()->user()->type == 'TP001') {
    $menu->add("User Control",array('nickname' => "user",'class'=>'treeview'))
    ->append(' <b class="caret"></b>')
    ->prepend('<span class="glyphicon glyphicon-user"></span> ');
    
    $menu->user->add('Daftar User','user/list');
    $menu->user->add('Tipe User','user/type');
}else{
    ---
}

The script above I cants see the menu with the condition even I already login with 'TP001' (always in else), then I try to fix my code with this

auth()->user()->isDeveloper()

and i adding this in my model

public function isDeveloper()
    {
        return ($this->type == 'TP001');
    }

I already add this use auth;

But still not working, is there any way to give the condition like above but in a correct way? Thanks in advance and sorry for my bad English.

Please sign in or create an account to participate in this conversation.