Condition in laravel 5 Middleware always false

Viewed 1432

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 {
    /* Some code here...*/
}

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

My model

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

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.

My Kernel

  protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\Frontend::class,
  ];
3 Answers
Related