I have 3 tables. tasks, items, and item_types
A task belongs to an item
An item belongs to item_type
task: has item_id
item: has item_type_id
As far as I understand, we don't have belongsToThrough relationship.
Starting from tasks, I am trying to get item_type.
$tasks = Task::with('item')->get() // this works with belongsTo relationship
I have seen some people achieving this with hasManyThrough. But when I try this:
class Task {
public function itemType() {
return $this->hasOneThrough('App\ItemType', 'App\Item');
}
}
This doesn't work:
$tasks = Task::with('item')->with('itemType')->get()
Call to undefined relationship [ItemType] on model [App\Task].
What is the way of achieving this?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hx2d5P
via IFTTT
Aucun commentaire:
Enregistrer un commentaire