0

I'm wanting to only show links if the logged in user has a "1" on the admin column from the users table.

What I've tried:

In my User.php

public function isAdmin(){
    if(Auth::User()->administrator == 1){
        return true;
    }else{
        return false;
    };
}

My migration:

Schema::create('users', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('firstname');
    $table->string('lastname');
    $table->boolean('administrator')->default(0);
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

My Blade:

@if(Auth::check())
  @if ({{User::isAdmin()}})
    <a href="/admin">some link for admins only</a>
  @endif
@endif

The link doesn't show up no matter who logs in.

atymic
  • 3,093
  • 1
  • 13
  • 26
Auron Kelmud
  • 51
  • 1
  • 8
  • You can simply do `return Auth::user()->administrator == 1;` in your `isAdmin()` method (becomes `return false;` for non-admins and `return true` for admins). That said, what is the `dd(Auth::user()->administrator);`? – Qirel Jul 28 '19 at 20:19
  • it shows up as 0 even with a user that has an administrator == 1 – Auron Kelmud Jul 28 '19 at 20:24
  • ahhh I figured it out. Whenever I was creating another Model called "Instructor," it creates a User as well but I just forgot to include the "administrator = 1" within that Create. dd to the rescue. Thanks – Auron Kelmud Jul 28 '19 at 20:29

0 Answers0