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