vendredi 30 avril 2021

Get Departmenr name from department id using eloquent laravel

I have this user table

id | name |      email     | department_id

1    user 1  xyz@gmail.com        2

and this is department table

id |  department_name 

1      Admin 
2      Account

there is salary table :

id |  user_id |  basic_pay

1        1          5000

I have this employee relation in salary model

class Salary extends Model
{
   public function employee(){
      return $this->belongsTo('App\User','user_id','id');
   }
}

I want to get department name also to which user is associated

  $Data =  Salary::where('id',$id)->with('employee')->first();

but presently i can only get department_id with the help of employee relation.

Any help is highly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire