/** * Remove the specified resources from storage. * * @access public * * @param $modelName * @return \Illuminate\Http\RedirectResponse */ public function multiDestroy($modelName) { if (Gate::denies($modelName . '.delete')) { return view('crud::errors.403'); } $items = Input::get('delete'); $modelNameWithNamespace = $this->setModelNamespace($modelName); $model = Master::getInstance($modelNameWithNamespace); if (count($items) === 0) { return Redirect::route('crud.index', $modelName); } foreach ($items as $id => $item) { $model->buildForm($id)->getFormBuilder()->destroy(); } // Set the flash message Session::flash('message.success', trans('crud::messages.success.model-deleted', ['count' => count($items) > 1 ? 'multiple' : 'one', 'model' => $model->getModelPluralName()])); // afterMultiDestroy hook if (method_exists($model, 'afterMultiDestroy')) { return $model->afterMultiDestroy(Redirect::route('crud.index', $modelName)); } return Redirect::route('crud.index', $modelName); }
/** * Remove the specified resources from storage. * * * @param $modelName * * @return \Illuminate\Http\RedirectResponse */ public function multiDestroy($modelName) { if (!\Auth::user()->hasPermission($modelName . '.delete')) { abort(403); } $items = Input::get('delete'); $controllerName = $this->setModelNamespace($modelName); $modelDescriptor = Master::getInstance($controllerName); $modelNameWithNamespace = $modelDescriptor->getModelFullName(); if (count($items) === 0) { return response()->json(['result' => false]); } foreach ($items as $id) { /** @var Model $model */ $model = $modelNameWithNamespace::find($id); $model->delete(); } /* foreach ($items as $id => $item) { $model->buildForm($id) ->getFormBuilder() ->destroy(); } */ // afterMultiDestroy hook if (method_exists($modelDescriptor, 'afterMultiDestroy')) { return $modelDescriptor->afterMultiDestroy(Redirect::route('crud.index', $modelName)); } return response()->json(['result' => true, 'count' => count($items) > 1 ? 'multiple' : 'one', 'model' => $modelDescriptor->getModelPluralName()]); }
/** * Show the form for deleting a resource. * * @param string $modelName * * @access public * @return $this */ public function delete($modelName) { $modelNameWithNamespace = sprintf($this->nameSpace . '%sController', $modelName); $master = Master::getInstance($modelNameWithNamespace)->buildForm(); return view('crud::modals.delete', ['name' => $modelName, 'model' => $master]); }