/** * @param CrudController $controller */ public function showHelp(CrudController $controller) { if ($controller->getFormBuilder()->getElements()) { return; } Config::set('crud::config.view.create', 'admin::crud.help'); }
/** * Seed the form with defaults that are stored in the session * * @param Model $model * @param CrudController $crudController */ public function onCrudSaved(Model $model, CrudController $crudController) { $fb = $crudController->getFormBuilder(); foreach ($fb->getElements() as $name => $element) { if (!$element instanceof FileElement) { continue; } if ($model instanceof File) { $file = $model; } else { $file = new File(); } if ($uploaded = Input::file($name)) { // Save the file to the disk $uploaded->move(storage_path($element->getPath()), $uploaded->getClientOriginalName()); // Update the file model with metadata $file->name = $uploaded->getClientOriginalName(); $file->extension = $uploaded->getClientOriginalExtension(); $file->size = $uploaded->getClientSize(); $file->path = $element->getPath() . '/' . $uploaded->getClientOriginalName(); $file->save(); if (!$model instanceof File) { $model->{$name} = $element->getPath() . '/' . $uploaded->getClientOriginalName(); $model->save(); } } } }
/** * @param CrudController $controller */ public function buildModel(CrudController $controller) { $mb = $controller->getModelBuilder(); foreach ($controller->getFormBuilder()->getElements() as $element) { $this->buildFormElement($element, $mb); } }