vendredi 3 août 2018

accessing relationship from model laravel

i have a two tables where user table has a one to one relationship with role table

this is my user model

public function role(){
    return $this->belongsTo(Role::class);
}

this is my role model

public function user(){
    return $this->hasOne(User::class);
}

this my table structure for role

enter image description here

this my table structure for user

enter image description here

how can i access in my user model the role which is equal to employee i tried

User::with('role')->where('role_name','employee')->get();

but it has an error

role_name column not found



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire