Back

Converting raw sql query to laravel eloquent


Hi everybody,

This is my first question to any forum ever, so please excuse me for any mistakes. I am currently working on a room booking system where I need to check availability of the rooms for a user specified slot. There are three tables as rooms, bookings and users. Below is my raw sql query in mysql and I want to convert it to eloquent. I have tried thinking in several different ways but unable to do so

Please help

SELECT rooms.location, rooms.id, rooms.name, users.name, IF( ( bookings.status = 'booked' AND( NOT( bookings.end_time <= '2017-05-30 12:00:00' OR bookings.start_time >= '2017-05-30 12:35:00' ) OR( bookings.recurring = 1 AND DATE(bookings.start_time) <= '2017-05-30' AND NOT( TIME(bookings.end_time) <= '12:00:00' OR TIME(bookings.start_time) >= '12:35:00' ) ) ) ), 'Booked', 'Available' ) AS 'Status', bookings.recurring, bookings.start_time, bookings.end_time FROM rooms LEFT JOIN bookings ON rooms.id = bookings.room_id LEFT JOIN users ON bookings.user_id = users.id ORDER BY STATUS DESC , bookings.start_time ASC, rooms.id ASC

Chekout below to see the formatted code

Formatted Code

sbimochan replied 11 months ago

COMPLEX


Sign in to participate in this thread!


We'd like to thank these amazing companies for supporting us