mozg
mozg

Reputation: 269

Laravel 4 ManyToMany where

I have 3 tables:

If I want to take products with series = 3:

Series::find(3)->products;

Produced sql query:

SELECT *
FROM `products`
INNER JOIN `product_series`
ON `products`.`id` = `product_series`.`product_id`
WHERE `product_series`.`series_id` = '3'

The question is how can I take products where series_id != 3 with Eloquent?
The sql query is smth like:

SELECT *
FROM `products`
INNER JOIN `product_series`
ON `products`.`id` = `product_series`.`product_id`
WHERE `product_series`.`series_id` != '3'

Upvotes: 0

Views: 50

Answers (1)

TAHQ69
TAHQ69

Reputation: 21

You may try this:

$series = Series::where('id', '!=', 3)->with('products')->get();

Upvotes: 1

Related Questions