skip to Main Content

i am trying to make @admin @endadmin in view to control some access in my project

@admin

<li class="nav-item">
    <a class="sidebar-link {{ Str::startsWith($route,'role.index') ? 'actived' : '' }} " href="{{ route('role.index') }}">
        <span class="icon-holder">
            <i class="c-brown-500 ti-user"></i>
        </span>
        <span class="title">roles</span>
    </a>
</li>

@endadmin

and in app service provider in boot function

Blade::if('admin',function(){

    return auth()->check() && auth()->user()->isposs();
});

and in user model:

 public function isposs(){
     return $this->role->id==10:
 }

i need to make simple cms

2

Answers


  1. Create a scope inside of your User model

    public function scopeIsPoss(Builder $query){
        return $query->role->id == 10;
    }
    

    then you can call

    auth()->user()->isPoss();
    
    Login or Signup to reply.
  2. It seems like $this->role is an int value. So first check that with dd($this->role) to see the real value.

    The error message says that it cannot access id prop on an int value like i.e.: 9, you cannot do $this->9->id.

    $this->role must return a relationship or something, more like a class, instead of an int.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search