How to convert SQL query to Laravel Eloquent?

Viewed 108

One of our teams asked this question earlier today, and there are no right answers still. Perhaps the way he worded the question wasn't correct — all in all this the SQL query I want to convert to Laravel Eloquent.

SELECT * FROM drivers 
    where driver_number 
NOT IN (SELECT driver_number FROM buses) 
    AND station_id = 2 OR driver_number = 'Dr_02'
1 Answers

try this.

Driver::whereNotIn('driver_number',Buse::select('driver_number'))
       ->where('station_id',2)
       ->orWhere('driver_number','Dr_02');

if the Buse select gives you an error, add the get method at the end of it

Buse::select('driver_number')->get()
Related