Converting raw sql query to laravel eloquent
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
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
Want to reply to this thread?Login with github.