mardi 12 mai 2020

how to show just Admin name from users table in laravel

i have a user table :

user table

and i have a realtion between user and roles :

role Model :

public function users()
{
    return $this->belongsToMany(User::class);
}

user Model :

public function roles()
{
    return $this->belongsToMany(Role::class);
}

and i have view for show users like this :

<select class="col-12 border mt-2 pt-2" name="reciever">
        @foreach($users as $user)
                <option value=""></option>
        @endforeach
</select>

and this is controller :

$users = User::all();
return view('Form1.add', compact('users'));

but in view, i want to show just user with role Admin, how can i do this ?

this is role table :

role table

and this is pivot table between user and role like this :

pivot table between users and roles

i just want to show user with Admin role.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire