I have a small Laravel app with several users and different roles.
What I want is to have a different page to display the users according to their roles (a page to see the admins, a page to see the students etc...)
I have a Users table
(of course), a Roles table
and a role_user table
Roles :
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
role_user table :
Schema::create('role_user', function (Blueprint $table) {
$table->id();
$table->BigInteger('role_id')->unsigned()->onDelete('cascade');
$table->BigInteger('user_id')->unsigned()->onDelete('cascade');
$table->timestamps();
});
I know that it will seem easy to a lot of you, but not to me. I'm stuck...
Thanks a lot !
you can do it using double join:
or the better solution is using laravel many to many relation
after building the relation like in doc, you can do it using whereHas: