public function getKitBookings() { if (!Request::ajax()) { return "not a json request"; } $index = Input::get('ID'); $query = "select " . " concat(K.Name, ' - ', K.SpecializedName) as 'Name'," . " B.ID as 'ID'," . " B.KitID as 'KitID'," . " B.ForBranch as 'ForBranch'," . " B.Purpose as 'Purpose'," . " B.ShadowStartDate as 'ShadowStartDate'," . " B.ShadowEndDate as 'ShadowEndDate'," . " B.StartDate as 'StartDate'," . " B.EndDate as 'EndDate' " . "from Booking as B" . " inner join Kits as K" . " on B.KitID = K.ID " . "where B.KitID = '" . $index . "'"; $bookings = DB::select(DB::raw($query)); foreach ($bookings as $booking) { $user = BookingDetails::select('UserID')->where('BookingID', $booking->ID)->where('Booker', 1)->first(); $recipients = BookingDetails::where('BookingID', $booking->ID)->where('Booker', 0)->get(); $booking->UserID = $user->UserID; $booking->KitRecipients = $recipients; } return $bookings; }