Example #1
0
 public function postDelete(Request $request)
 {
     $logged_in_user = \Auth::user();
     //find the user that is logged in
     $holiday_mod = \App\Holiday::find($request->id);
     //get the holiday from the DB
     $holidayToDelete = \App\Holiday::with('escapes')->where('id', '=', $request->id)->get();
     //get the holiday and the escapes
     $holiday_mod->escapes()->sync([]);
     //remove the escapes from the pivot table escape_holiday
     $holiday_mod->delete();
     //delete the holiday
     //iterate over the escapes and delete them from the escape table
     foreach ($holidayToDelete[0]['escapes'] as $escape) {
         $escapeToDelete = \App\Escape::find($escape->id);
         $escapeToDelete->delete();
     }
     //send the user back to the holiday create page
     return redirect('holiday/create');
 }
Example #2
0
 public function postDelete(Request $request)
 {
     //gets the holiday that the escape belongs to
     $holiday = \App\Holiday::find($request->holiday_id);
     //loads the escape to be delete
     $escapeToDelete = \App\Escape::find($request->id);
     //detaches the escape from the holiday
     $holiday->escapes()->detach($request->id);
     //deletes the escape
     $escapeToDelete->delete();
     //load the holiday with its escapes
     $holidayWithEscapes = \App\Holiday::with('escapes')->where('id', '=', $request->holiday_id)->get();
     return redirect('holiday/create');
 }