LEFT JOIN with AND at Eloquent Laravel 5

2

I have a query with Left Join with AND I am not able to implement this in laravel 5.

An excerpt from the query:

LEFT JOIN visitante v ON a.codigo = v.id 
AND v.data BETWEEN '2015-06-01' and '2016-05-31' and v.status = '1'

I tried this way but it did not work:

->leftJoin(DB::raw('visitante v ON a.codigo = v.id
AND v.data BETWEEN \'2015-06-01\' and \'2016-05-31\' and v.status = \'1\''))
    
asked by anonymous 25.11.2016 / 15:38

1 answer

2

I was able to resolve this way!

->leftJoin('visitante as v', function($join) 
            {

                $join->on('a.codigo', '=', 'v.id');

                $join->on('v.data','>=',DB::raw("'2015-06-01'"));
                $join->on('v.data','<=',DB::raw("'2016-05-31'"));
                $join->on('v.status','=',DB::raw("'1'"));

            })
    
28.11.2016 / 15:46