How to conduct a double consultation on laravel?

1

I have a query in SQL Ansi:

select * from payments as P, receipts as R 
where P.created_at < CURRENT_DATE AND P.updated_at < CURRENT_DATE AND R.created_at < CURRENT_DATE AND R.updated_at < CURRENT_DATE

Precious to perform the same query in laravel:

public function relatorioBI(){

        //1 A pagar

        $query = $this->newQuery();

        $query->where('created_at','1');

        return $this->doQuery($query, $take, $paginate);
    }

I need to perform the query in both tables, and test the conditional value!

    
asked by anonymous 24.10.2017 / 22:51

1 answer

1

Use \DB::select than the simple way to perform queries like this:

Example:

$sql = ' select * from payments as P, receipts as R ';
$sql .= ' where P.created_at < CURRENT_DATE AND P.updated_at < CURRENT_DATE ';
$sql .= ' AND R.created_at < CURRENT_DATE AND R.updated_at < CURRENT_DATE';

$users = \DB::select($sql);  

Note: in the site already exists several examples see link .

If you need to use parameters, follow the example . :

\DB::select('select * from users where active = ?', [1]);

or , a array according to the sequence and amount of parameter ( ? ).

Reference Running Raw SQL Queries

    
25.10.2017 / 15:02