jeudi 23 août 2018

Get data through a relationship with laravel

I have 2 tables (users) and (analyst_evaluations), through a relationship with laravel I try to get the name of the user to whom the evaluation was done, in the following way

Model users

public function analyst(){

    return $this->belongsTo('App\EvaluationsAnalyst');

}

Model EvaluationsAnalyst

public function user(){

    return $this->hasMany('App\User', 'analyst_id');

}

I try to get the name like this

$user = EvaluationsAnalyst::where('analyst_id', '=', '16970772')->first();

echo $user->analyst->name;

but I throw the following error

Trying to get property of non-object

What am I doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire