0
votes

User model:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Zizaco\Entrust\HasRole;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use HasRole;

Role Model:

<?php

use Zizaco\Entrust\EntrustRole;

class Role extends EntrustRole
{

}

Permission Model:

<?php

use Zizaco\Entrust\EntrustPermission;

class Permission extends EntrustPermission
{

}

User controller:

public function postSignin(){
        if (Auth::attempt(array('email'=>Input::get('email'),
                                'password'=>Input::get('password')))) {

            $id         = Auth::user()->id;
            $user       = User::where('id','=',$id);
            $firstname = Auth::user()->firstname;

            if ($user->hasRole("User_Not_Approved")) {
                return Redirect::intended('/users/dashboard');
                    }

Error message:

BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::hasRole()

The error message is presented when the IF statement is running, whilst the user is logging in. I have followed Entrust's instructions, but I am at a loss as to why it isn't picking up the method.

Any help would be hugely appreciated!

1

1 Answers

0
votes

Try changing: $user = User::where('id','=',$id); to $user = User::find($id);

User::where would need ->get to return what you want, and even then it would return a collection; you would want something like User::where(etc)->first(); to ensure you got a single instance of User. In reality though, since you are retrieving by id, that is what ->find($id) is designed for, and what you should do.