i have custom auth works fine. can use in routes blocking or releasing access. hide or show buttons , links roles , users, like:
@if(user==admin) // line (auth::user->roles()) ?? <a href="admin">configuration</a @endif
but sadly cant no matter how try it. said have user model
public function roles() { return $this->belongstomany('app\role', 'user_role', 'user_id', 'role_id'); } public function hasanyrole($roles) { if (is_array($roles)) { foreach ($roles $role) { if ($this->hasrole($role)) { return true; } } } else { if ($this->hasrole($roles)) { return true; } } return false; } public function hasrole($role) { if ($this->roles()->where('name', $role)->first()) { return true; } return false; }
but not know how call functions blade view since im starter in laravel. great, thank you. bye
try this
@if(\auth::check() && \auth::user()->hasrole('admin')) <a href="admin">configuration</a @endif
Comments
Post a Comment