]> _ Git - cubist_cms-back.git/commitdiff
wip #2683 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 May 2019 17:06:48 +0000 (19:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 May 2019 17:06:48 +0000 (19:06 +0200)
src/app/Http/Controllers/CubistModelCrudController.php [new file with mode: 0644]
src/app/Http/Requests/ModelRequest.php [new file with mode: 0644]
src/app/Models/CubistModel.php [new file with mode: 0644]
src/database/2019_05_20_161943_create_models_table.php [new file with mode: 0644]
src/routes/cubist/backpack/model.php [new file with mode: 0644]

diff --git a/src/app/Http/Controllers/CubistModelCrudController.php b/src/app/Http/Controllers/CubistModelCrudController.php
new file mode 100644 (file)
index 0000000..6d738f8
--- /dev/null
@@ -0,0 +1,61 @@
+<?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;
+    }
+}
diff --git a/src/app/Http/Requests/ModelRequest.php b/src/app/Http/Requests/ModelRequest.php
new file mode 100644 (file)
index 0000000..a6acfc8
--- /dev/null
@@ -0,0 +1,55 @@
+<?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 [
+            //
+        ];
+    }
+}
diff --git a/src/app/Models/CubistModel.php b/src/app/Models/CubistModel.php
new file mode 100644 (file)
index 0000000..f42c07f
--- /dev/null
@@ -0,0 +1,59 @@
+<?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
+    |--------------------------------------------------------------------------
+    */
+}
+
diff --git a/src/database/2019_05_20_161943_create_models_table.php b/src/database/2019_05_20_161943_create_models_table.php
new file mode 100644 (file)
index 0000000..c1d7a43
--- /dev/null
@@ -0,0 +1,33 @@
+<?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');
+    }
+}
diff --git a/src/routes/cubist/backpack/model.php b/src/routes/cubist/backpack/model.php
new file mode 100644 (file)
index 0000000..70b3798
--- /dev/null
@@ -0,0 +1,9 @@
+<?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