From: Vincent Vanwaelscappel Date: Mon, 20 May 2019 17:06:48 +0000 (+0200) Subject: wip #2683 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6d898f79a7ea43b8ba393f32294e43e6c5ea6f89;p=cubist_cms-back.git wip #2683 @1 --- diff --git a/src/app/Http/Controllers/CubistModelCrudController.php b/src/app/Http/Controllers/CubistModelCrudController.php new file mode 100644 index 0000000..6d738f8 --- /dev/null +++ b/src/app/Http/Controllers/CubistModelCrudController.php @@ -0,0 +1,61 @@ +crud->setModel('App\Models\CubistModel'); + $this->crud->setRoute(config('backpack.base.route_prefix') . '/model'); + $this->crud->setEntityNameStrings('model', 'models'); + + /* + |-------------------------------------------------------------------------- + | CrudPanel Configuration + |-------------------------------------------------------------------------- + */ + + // TODO: remove setFromDb() and manually define Fields and Columns + $this->crud->setFromDb(); + + // add asterisk for fields that are required in ModelRequest + $this->crud->setRequiredFields(StoreRequest::class, 'create'); + $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); + } + + public function store(StoreRequest $request) + { + // your additional operations before save here + $redirect_location = parent::storeCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } + + public function update(UpdateRequest $request) + { + // your additional operations before save here + $redirect_location = parent::updateCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } +} diff --git a/src/app/Http/Requests/ModelRequest.php b/src/app/Http/Requests/ModelRequest.php new file mode 100644 index 0000000..a6acfc8 --- /dev/null +++ b/src/app/Http/Requests/ModelRequest.php @@ -0,0 +1,55 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/app/Models/CubistModel.php b/src/app/Models/CubistModel.php new file mode 100644 index 0000000..f42c07f --- /dev/null +++ b/src/app/Models/CubistModel.php @@ -0,0 +1,59 @@ +increments('id'); + $table->string('name')->unique(); + $table->string('label'); + $table->json('attributes'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('models'); + } +} diff --git a/src/routes/cubist/backpack/model.php b/src/routes/cubist/backpack/model.php new file mode 100644 index 0000000..70b3798 --- /dev/null +++ b/src/routes/cubist/backpack/model.php @@ -0,0 +1,9 @@ + config('backpack.base.route_prefix', 'admin'), + 'middleware' => ['web', config('backpack.base.middleware_key', 'admin')], + 'namespace' => 'App\Http\Controllers\Admin', +], function () { // custom admin routes + CRUD::resource('model', 'CubistModelCrudController'); + CRUD::resource('model', 'CubistModelCrudController'); +}); // this should be the absolute last line of this file