tomasosho
6 months ago
340
3
Laravel

i want to display only users that have a certain role

Posted 6 months ago by tomasosho

I have linked my user table and role table now i have role_user table with the structure

CREATE TABLE role_user (
    id         INTEGER  NOT NULL
                        PRIMARY KEY AUTOINCREMENT,
    role_id    INTEGER  NOT NULL,
    user_id    INTEGER  NOT NULL,
    created_at DATETIME,
    updated_at DATETIME
);

I want to display only users with role_id of 2

E.g.

$users = User::where('role_id', 2)->paginate(4);
or
$displayusers = DB::table('users')->select('role_user')->where('role_id', '4')->paginate(4);

Both are giving me empty arrays.

What can i do?

Please sign in or create an account to participate in this conversation.