jeudi 2 août 2018

querying relations in laravel

I'm practicing laravel and im confused in querying relations I have two tables (users and roles)

in my user model i have

use SoftDeletes;

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

and in my role model i have

use SoftDeletes;

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

this is my table structure for role

enter image description here

and this my table structure for users

enter image description here

how can i query the roles base on users table



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire