A
A
akdes2017-05-12 18:18:15
MySQL
akdes, 2017-05-12 18:18:15

M:n in Laravel 5.4 controllers?

Good day to all.
Need support in many to many relationships in laravel.
Next scenario.
There is a network of shops
shops:
id
name
..
there are entrepreneurs:
id
name
..
there is an m:n connection between them, while shops can exist without entrepreneurs and vice versa.
There is a Customer controller

public function locationByCustomer(Customer $customer)
    {
        $customer->shops(); //Shop-Model -> belongsToMany(Customer) 

        return $customer;
    }

question:
How to get a list of stores that !not! involved with entrepreneurs?
those. in SQL directly I would do this:
select id, name from shops where id not in (select shop_id from shop_customer)

I have no experience with Laravel, I'm stupid about trifles. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hakkol, 2017-05-12
@akdes

If I understand the question correctly, then:
$shops = Shop::doesntHave('customer')->get();

H
hopeful_romantic, 2017-05-12
@hopeful_romantic

https://github.com/laravel/framework/issues/3413

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question