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
Create a scope inside of your
User
modelthen you can call
It seems like
$this->role
is an int value. So first check that withdd($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.