dilfdo
3 years ago

converting mysql query to Laravel

Posted 3 years ago by dilfdo

Please advice how to convert below query to laravel

SELECT * FROM shifts WHERE time_sheet_id = 11 AND 
(
 "04:00" BETWEEN shift_start_time AND shift_end_time OR
 "05:00" BETWEEN shift_start_time AND shift_end_time OR
 "04:00" >= shift_start_time AND "05:00" <= shift_end_time



 )

this is what i tried , but it gives errors

  $shiftData = Shifts::where('time_sheet_id', '=', $getTimesheet1->time_sheet_id)
            ->where('user_id', '=', $user_id->user_id)
            ->where('role_id', '=', 1)
            ->whereBetween(Input::get('shift_start_time'), array('shift_start_time ' , 'shift_end_time '))
            ->whereBetween(Input::get('shift_end_time') , array('shift_start_time ' , 'shift_end_time '))
            ->where( Input::get('shift_end_time'), '>=', 'shift_start_time ')
            ->where(Input::get('shift_end_time'), '<=',  'shift_end_time ')
            ->get();

error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '18:00:00' in 'where clause' (SQL: select * from `shifts` where `time_sheet_id` = 12 and `user_id` = 2 and `role_id` = 1 and `18:00:00` between shift_start_time and shift_end_time and `20:00:00` between shift_start_time and shift_end_time and `20:00:00` >= shift_start_time and `20:00:00` <= shift_end_time )
                    
                    
    ```                
                    

Please sign in or create an account to participate in this conversation.