Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

How to get current user's role in Laravel 5.2 ? #152

Open
zwl1619 opened this issue Feb 28, 2016 · 3 comments
Open

How to get current user's role in Laravel 5.2 ? #152

zwl1619 opened this issue Feb 28, 2016 · 3 comments

Comments

@zwl1619
Copy link

zwl1619 commented Feb 28, 2016

User:

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract

{
    use Authenticatable, CanResetPassword, HasRoleAndPermission;

    protected $fillable = [
        'name', 'email', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

}

Controller:

public function index()
    {
        $user = \Auth::user();
        $name=$user->name;
        $role = $user->getRoles();
      //  return view('index', compact('name','role'));
        dd($role);
    }

Result:

Collection {#370 ▼
  #items: []
}
@densityx
Copy link

densityx commented Mar 1, 2016

Try this

$user = App\User::first();
$user->getRoles();

@Isfirs
Copy link

Isfirs commented Apr 8, 2016

What is the output, if you add $name to the dd()?
Can you provide some information about the schema and the filled data? (Tables: user, roles, user_roles)

@johannesschobel
Copy link

Maybe this issue is related to #183 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants