G
G
GrimJack2017-07-07 11:25:59
MySQL
GrimJack, 2017-07-07 11:25:59

Why does the query built in the query builder work in the console, but does not work when executed by the builder?

I have a request that looks like this:

DB::table('company_user as a')
            ->join('company_user as c', 'a.data', '=', 'c.data')
            ->where('a.company_id', '!=', 'c.company_id')
            ->where('a.field_name', '=', 'user_email')
            ->where('a.data', '!=', '')
            ->where('c.data', '!=', '')
            ->get();

If we use toSql() instead of ->get , we get the following code:
select * from `company_user` as `a` 
inner join `company_user` as `c` 
on `a`.`data` = `c`.`data` 
where `a`.`company_id` != `c`.`company_id` 
and `a`.`field_name` = 'user_email' 
and `a`.`data` != '' 
and `c`.`data` != '';

And now the most interesting thing, if you execute get (), then it stupidly displays the entire table, and if you execute sql code in the console, everything is ok. What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question