Reputation: 381
So I've got 3 tables. But Laravel fails to link the tables to eachother, I feel like I'm missing a really small thing but I can't seem to find it.
Controller
$data = Item::all();
$clipper = $data->first();
dd($clipper->attributes());
Item
protected $table = 'item';
protected $primaryKey = 'item_id';
public $timestamps = false;
public function attributes() {
return $this->hasMany('App\Attributes', 'item_id');
}
Atrributes
protected $table = 'attributes';
protected $primaryKey = 'attr_id';
public $timestamps = false;
public function name() {
return $this->hasOne('App\Attributesname', 'name_id');
}
Attributes Name
protected $table = 'item_attributes';
protected $primaryKey = 'item_attr_id';
public $timestamps = false;
Result of dd
Database design
Upvotes: 0
Views: 67
Reputation: 8560
Laravel links relations fine, see you output parent model is the Item, related model is the Atribute, try this to see related data (not relation) :
$data = Item::all();
$clipper = $data->first();
dd($clipper->attributes);
Upvotes: 1