--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use Backpack\CRUD\app\Http\Controllers\CrudController;
+
+// VALIDATION: change the requests to match your own file names if you need form validation
+use App\Http\Requests\CubistModelRequest as StoreRequest;
+use App\Http\Requests\CubistModelRequest as UpdateRequest;
+use Backpack\CRUD\CrudPanel;
+
+/**
+ * Class ModelCrudController
+ * @package App\Http\Controllers\Admin
+ * @property-read CrudPanel $crud
+ */
+class CubistModelCrudController extends CrudController
+{
+ public function setup()
+ {
+ /*
+ |--------------------------------------------------------------------------
+ | CrudPanel Basic Information
+ |--------------------------------------------------------------------------
+ */
+ $this->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;
+ }
+}
--- /dev/null
+<?php
+
+namespace app\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class CubistModelRequest extends FormRequest
+{
+ /**
+ * Determine if the user is authorized to make this request.
+ *
+ * @return bool
+ */
+ public function authorize()
+ {
+ // only allow updates if the user is logged in
+ return backpack_auth()->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 [
+ //
+ ];
+ }
+}
--- /dev/null
+<?php
+
+
+namespace app\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+use Backpack\CRUD\CrudTrait;
+
+class CubistModel extends Model
+{
+
+ use CrudTrait;
+
+ /*
+ |--------------------------------------------------------------------------
+ | GLOBAL VARIABLES
+ |--------------------------------------------------------------------------
+ */
+
+ protected $table = 'cubist_models';
+ // protected $primaryKey = 'id';
+ // public $timestamps = false;
+ // protected $guarded = ['id'];
+ protected $fillable = ['name', 'label', 'attributes'];
+ // protected $hidden = [];
+ // protected $dates = [];
+
+ /*
+ |--------------------------------------------------------------------------
+ | FUNCTIONS
+ |--------------------------------------------------------------------------
+ */
+
+ /*
+ |--------------------------------------------------------------------------
+ | RELATIONS
+ |--------------------------------------------------------------------------
+ */
+
+ /*
+ |--------------------------------------------------------------------------
+ | SCOPES
+ |--------------------------------------------------------------------------
+ */
+
+ /*
+ |--------------------------------------------------------------------------
+ | ACCESORS
+ |--------------------------------------------------------------------------
+ */
+
+ /*
+ |--------------------------------------------------------------------------
+ | MUTATORS
+ |--------------------------------------------------------------------------
+ */
+}
+
--- /dev/null
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateModelsTable extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('cubist_models', function (Blueprint $table) {
+ $table->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');
+ }
+}
--- /dev/null
+<?php
+Route::group([
+ 'prefix' => 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