samedi 29 août 2015

How to use hasManyThrough relationship in Laravel?

I have the following tables in my schema:

orders |order_items | users | items | providers

orders has a user_id.

order_items has order_id and item_id.

items has provider_id.

Now, how do I fetch all the orders (eager loaded) with order_items, items, students and providers.

I've tried using the hasManyThrough method of Laravel Eloquent but it didn't work. Like this:

//Order.php Eloquent Model
public function items()
    {
        return $this->hasManyThrough('App\Item','App\OrderItem','item_id','id');
    }

I added the hasManyThrough method to other models as necessary.

Can someone help me through? Just give me a hint and I'll pick it up.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1JtzdTd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire