A
A
Abc Edc2015-09-16 20:04:31
Laravel
Abc Edc, 2015-09-16 20:04:31

How to make such a selection on laravel (without using raw)?

blob
Unsuccessful attempt

$query = DB::table('A')
            ->leftJoin('B', 'A.id', '=', 'B.A_id')
            ->whereNull('B.A');
        if ($id)
            $query->orWhere('A_id', $id);
        return $query->get();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gregory, 2015-09-16
@gleber1

What request is the Builder generating? You can see it like this ( from here ):

DB::connection()->enableQueryLog();
//To get an array of the executed queries, you may use the getQueryLog method:
dd(DB::getQueryLog());

Compare with what should be.
Personally, I sin on whereNull('B.A');instead of whereNull('B.A_id');.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question