V
V
Vladimir Krauz2017-03-12 16:31:05
Laravel
Vladimir Krauz, 2017-03-12 16:31:05

Laravel. How to use leftJoin?

Good afternoon.
I have this sql query:

SELECT * FROM books AS e LEFT JOIN authors AS s ON e.authorid = s.id WHERE e.type = 2 AND s.authorid = 1

It needs to be translated into laravel orm:
(It turned out like this for me :)
$beginGames = event::where('books.type', '=',  DB::raw(2))
            ->leftJoin('authors as authors', 'authors.authorsid', '=', DB::raw(1))
            ->get();

I know that there is another way through links and models, but I have no idea how to do it.
So, if you make a toSql () request from laravel, then the request will be approximately similar, but still not the same.
select * from `books` left join `authors` as `authors` on `authors`.`authorid` = 1 where `books`.`type` = 2

How to be? How to do it right and what is missing?
I would appreciate any help, thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2017-03-12
@Nc_Soft

\DB::select('SELECT * FROM books AS e LEFT JOIN authors AS s ON e.authorid = s.id WHERE e.type = ? AND s.authorid = ?', [2,1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question