How can I get the full model based on the foreign key in a table using Laravel?
A user row will have a single tier it's associated with, represented by the ID as the foreign key.
I need to return the user with the tier it belongs to, and the entire contents of that tier as well.
In my User model, I've tried protected $with = ['tier'];
, but this doesn't work.
User:
public function tier()
{
return $this->belongsTo('App\Tier');
}
Tier:
public function users()
{
return $this->hasMany('App\User');
}
User's table:
User's table structure fk index:
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire