Hey,
So from another thread I ended up watching this video https://laracasts.com/lessons/users-and-roles
My current apps don't need roles as I am the only ever logged in user, however it got me thinking and I have questions that I find too many different answers and as I rarely use pivots I am confused.
Assuming I have setup a test of the above video I have my tables all set up and everything works as it should. If you have not seen it we have tables for users, roles and the role_user table.
In the User model the relationship is defined as:
public function roles()
{
return $this->belongsToMany('App\Role');
}
Ok so what I want to do then is Authenticate the current user and capture the role or roles for that user. I see people saying ->withPivot others saying it's wrong and so on.
Really I suppose there are two things here,
- Simple capture of the role or roles to display them in a view
- Authenticate the user with his role
Sorry if this seems simple but I guess I read too many other discussions that my head has too many ways of doing this.
Apologies for no code examples, on train heading home.