E
E
Eugene2018-03-11 14:45:26
MySQL
Eugene, 2018-03-11 14:45:26

How to correctly compose a SQL query using Eloquent?

Tell me how to make a selection with the OR condition using Eloquent.
At the output, you need this query

select * from tableName where (event_id=50 and event_date > NOW()) or (event_id=50 and event_status=7451)

$schedulers = Schedule::with('status')->where('event_id', $eventId)->orWhere() ???;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Starkov, 2018-03-11
@atachrus

$shedulers = Shedule::where(function($query) use($eventId){
        $query->where('event_id', $eventId)
            ->where('event_date', '>', 'NOW()')
    })
    ->orWhere(function($query) use($eventId){
        $query->where('event_id', $eventId)
             ->where('event_status', 7451);
    })
    ->get();

Not sure if 'NOW()' should be wrapped in DB::raw('NOW()')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question