Perhaps like
return Supplier::has('products')->where('name', $name)->get();
or
return Product::has('suppliers')->where('name', $name)->get();
This should be what you're looking for- http://laravel.com/docs/4.2/eloquent#querying-relations
Don't make it more complicated that you need to.. just do
$supplier = Supplier::with('products')->whereName($name)->first();
return $supplier->products;
Thanks for the answers, it works like a charm!
I would like to know how this could have been achieved if the relationship was one-to-many? Say a supplier can have multiple products, but every product belongs to only one supplier..
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community