/** * Delete an existing location if no phone uses the model. */ public function delete($id) { $astPhonesWithLocation = astPhoneModel::where('PHONE_LOCATION_ID', '=', $id)->get(); if (count($astPhonesWithLocation) == 0) { $astPhoneLocation = astPhoneLocationModel::findOrFail($id); $astPhoneLocation->delete(); Session::flash('astMessage', 'Location has been deleted!'); return Redirect::route('locations'); } else { Session::flash('astDeleteMessage', 'In order to delete this location, all phones with this location must be deleted first.'); return redirect()->route('showLocation', [$id]); } }