Using PHP and Laravel 4 I have a method in my User model, as shown below, to test the Admin user ...
public function isAdmin() { if(isset($this->user_role) && $this->user_role === 'admin'){ return true; }else{ return false; } }
This does not work if I call this function in other classes or models.
To get the desired result, I had to do it like this ...
public function isAdmin() { if(isset(Auth::user()->user_role) && Auth::user()->user_role === 'admin'){ return true; }else{ return false; } }
I am trying to access this inside my Admin Controller, as shown below, but it returns an empty User object instead of the currently logged in User Object ...
public function __construct(User $user) { $this->user = $user; }
So my question is: how can I get the first version to work? When I create an instance of the User object in another class, I need to somehow make sure that it has data for the currently logged-in user, but I'm not sure if this is the best way ... I know that this is basic. I'm just a little rusty right now can use help, thanks
php laravel laravel-4
Jasondavis
source share