I finally managed to make middleware and login. Now I want to show all users from DB and show their roles (title of roles). How can I do this? I know it's possible with long query but I hope there is some better solution in Laravel :)
I have 3 tables in DB: users, roles, role_user (pivot)
User model:
public function roles()
{
return $this->belongsToMany('App\Role');
}
Role model:
public function users()
{
return $this->hasMany('App\User');
}
How can I show user's role in blade?
BTW: every user can have only one role...
@general If every user will only have one role, then my suggestion to you was to follow the structure that I mentioned above. That means restructuring your database to remove the pivot table and add role_id to the users table. Your example role_id method assumes that there is a pivot table. If you did restructure your database, then you can get a user's role_id by simply doing $user->role_id.
@thomaskim still get same error... I understand my first version but don't understand your version because there is no specified role_id column from users table anywhere in method...
can anyone help me, about, how to do log in system with role, user and permission table including one to many relationship?
i want to make two type of user admin & user.