Selecting the ID from the 3th table

I will explain what I have in the first section and then what I want to get.

I have those 3 tables:

first: users

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

the pivot table: user_to_role

protected $fillable = [
   'id', 'user_id', 'role_id'
];

and the third one: roles

protected $fillable = [
    'id', 'role_name', 
];

role_name is admin and client

When I login/register I want to show the view for the specific role of the user

but I don't really know how to do that in the controller, I have something like this but I know it's not good

public function index()
{
    if (Auth::user()->role_id==1) {
        // and something here which I don't know
        return view('homeadmin');
    }
}

I know I have to take the role id from the 3th table, make the connection with the pivot and then with the user but I don't really know how.



from Recent Questions - Stack Overflow https://ift.tt/3A6TwWx
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation