public function destroy($kitTypeID) { // This Shall be fun! // We have to deconstruct the types based on the forign key dependencys // First iterate all the kits, for each kit remove all contents, // and then all bookings (and all booking details) // then finally we can remove the kit type and then all the logs for that // kit type. foreach (Kits::where('KitType', '=', $kitTypeID)->get() as $kit) { foreach (KitContents::where("KitID", '=', $kit->ID)->get() as $content) { KitContents::destroy($content->ID); } foreach (Booking::where("KitID", '=', $kit->ID)->get() as $booking) { foreach (BookingDetails::where("BookingID", '=', $booking->ID)->get() as $detail) { BookingDetails::destroy($detail->ID); } Booking::destroy($booking->ID); } Kits::destroy($kit->ID); } KitTypes::destroy($kitTypeID); // Do the logs last, as all the deletes will log the changes of deleting the bits. Logs::where('LogKey1', '=', $kitTypeID)->delete(); return "OK"; }
public function destroy($kitID) { $kit = Kits::find($kitID); foreach (Booking::where('KitID', '=', $kitID)->get() as $book) { foreach (BookingDetails::where('BookingID', '=', $book->ID)->get() as $detail) { BookingDetails::destroy($detail->ID); } Booking::destroy($book->ID); } foreach ($kit->contents as $content) { KitContents::destroy($content->ID); } Kits::destroy($kitID); }
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; }