Thanks @Resin01 your answer was what I needed. But is there any way for me to get ell the features at once? by doing something like this $provider->offers->features ?
I have 3 models: Provider, Offer and Feature
And the relationships has been implemented as follow
Provider
class Provider extends Model
{
protected $table = 'providers';
protected $primaryKey = "ref_id";
public $incrementing = false;
protected $fillable = ['ref_id', 'name', 'description', 'status'];
public function offers() {
return $this->hasMany('App\Models\Offer');
}
}
Offer
class Offer extends Model
{
protected $primaryKey = "ref_id";
public $incrementing = false;
protected $fillable = [
'ref_id',
'name',
'description',
'base_id',
'sector_id',
'provider_id',
'category_id',
'status'
];
public function features() {
return $this->hasMany('App\Models\Feature');
}
}
Feature
class Feature extends Model
{
protected $fillable = [
'ref_id',
"name",
"dtype",
"value",
"description",
"offer_id"
];
public function offer() {
return $this->belongsTo('App\Models\Offer');
}
}