/**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return false;
     }
     return true;
 }
 /**
  * delete thumbnail file
  * @author Wojciech Jurkowski <*****@*****.**>
  */
 public function delete(ThumbnailRequest $request)
 {
     $crudeName = $request->input('crudeName');
     $crude = CrudeInstance::get($crudeName);
     $id = $request->input('model_id');
     $column = $request->input('model_column');
     $model = $crude->deleteThumbnailByIdAndColumn($id, $column);
     return ['model' => $model];
 }
 public function attributes()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return [];
     }
     if (!$crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) {
         return [];
     }
     return $crude->getCrudeSetup()->getTrans();
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return [];
     }
     if (!$crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) {
         return [];
     }
     $attr = $crude->getCrudeSetup()->getAddForm();
     return $crude->getValidationRules($attr, $this->all());
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return false;
     }
     if ($crude->cannotView()) {
         return false;
     }
     $model = $crude->getById($this->id);
     return $crude->canDelete($model);
 }
 /**
  * Call mathod to get first label for $attr autocomplete input
  * @param  Request $request - with
  *                          'crudeName' - crude class name
  *                          'attr'  - attribute name
  *                          'value' - model[attr]
  * @return JSON with string
  */
 public function label(AutocompleteRequest $request)
 {
     $crude = CrudeInstance::get($request->input('crudeName'));
     $attr = $this->underscoreToCamelCase($request->input('attr'));
     $value = $request->input('value');
     $methodName = 'label' . $attr;
     $result = '';
     if (method_exists($crude, $methodName)) {
         $result = call_user_func([$crude, $methodName], $value);
     }
     return response()->json($result, 200);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return false;
     }
     if ($crude->cannotOrder('check with permission')) {
         return false;
     }
     $this->crude = $crude;
     return true;
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return false;
     }
     if ($crude->cannotExport()) {
         return false;
     }
     $this->crude = $crude;
     return true;
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->input('crudeName'));
     if ($crude == null) {
         return false;
     }
     if (!$crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\ListInterface) {
         return false;
     }
     if (!$crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface) {
         return false;
     }
     return true;
 }
 /**
  * Download all files for model
  */
 public function downloadAll($crudeName = null, $id = null)
 {
     if (!$crudeName || !$id) {
         return redirect()->back();
     }
     $crude = CrudeInstance::get($crudeName);
     if (!$crude) {
         return redirect()->back();
     }
     $model = $crude->getModel()->find($id);
     if (!$model) {
         return redirect()->back();
     }
     $filesZip = CrudeZip::run($model);
     if (!$filesZip) {
         return redirect()->back();
     }
     return response()->download($filesZip, $crudeName . '-' . $id . '.zip')->deleteFileAfterSend(true);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $crude = CrudeInstance::get($this->crudeName);
     if ($crude == null) {
         return false;
     }
     if ($crude->cannotView()) {
         return false;
     }
     $model = $crude->getById($this->id);
     $permission = $this->action . 'CustomActionPermission';
     if (method_exists($crude, $permission) && !$crude->{$permission}($model)) {
         return false;
     }
     $method = $this->action . 'CustomAction';
     if (!method_exists($crude, $method)) {
         return false;
     }
     $this->crude = $crude;
     $this->model = $model;
     return true;
 }
 /**
  * Remove model
  */
 public function destroy(ApiDeleteRequest $request, $crudeName, $id)
 {
     $this->crude = CrudeInstance::get($request->crudeName);
     $model = $this->crude->deleteById($id);
     return $this->successResponse(['message' => trans('CrudeCRUD::crude.item_has_been_removed')]);
 }