Skip to content Skip to sidebar Skip to footer

Recuperating Roles Of Users From Database (foreign Key)

Can anyone tell me how i can recuperate roles of users from my database? Knowing i have 3 tables (Users, Roles, User_role) Migrations: Table users: public function up() {

Solution 1:

I recommend you using Laravel Models and relationships.

Here you have a relationship between Users and Roles. This relationship is defined in what is called an intermediate table, in this case the user_roles table.

There is a Many-to-Many type of relationship here between users and roles, where one user can have many roles and one role type can be assigned to many users.

I recommend you reading this: https://laravel.com/docs/5.2/eloquent-relationships#many-to-many

That's for Laravel 5.2, but you'll see that documentation for every Laravel 5.x version. There you'll learn how to build these relationships and how to use them effectively.

Post a Comment for "Recuperating Roles Of Users From Database (foreign Key)"