I have a Grade model that belongs to a User. So in my User I have a function
public function grades()
return $this->hasMany('App\Api\Models\Grade', 'user_id', 'id');
user_id is a foreignKey in the Grade model.
When I want to get a Grade I want to bring the User data back with it, but I cant manage it :).
In my Grade model I have:
public function user()
return $this->belongsTo('App\Api\Models\User', 'user_id', 'id');
the foreignKey I take it must be the key in the Grade table and the
id must be the key in the User table, I have tried every combination I can think, but there must be some simple logic to this.
In my GradeController I am passing in an
id to get the Grade,
$grade = Grade::find($id);
$gradeUser = $grade->user();
I am trying to assign
$gradeUser but never get a User