*/
public function boot()
{
- // define the routes for the application
- //$this->setupRoutes($this->app->router);
-
-// // only use the Settings package if the Settings table is present in the database
-// if (!\App::runningInConsole() && count(Schema::getColumnListing('settings'))) {
-// // get all settings from the database
-// $settings = Setting::all();
-//
-// // bind all settings to the Laravel config, so you can call them like
-// // Config::get('settings.contact_email')
-// foreach ($settings as $key => $setting) {
-// Config::set('settings.' . $setting->key, $setting->value);
-// }
-// }
-
- $this->publishes([__DIR__.'/database/migrations' => database_path('migrations')], 'migrations');
-
$this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'cubist_back');
foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) {
$this->loadRoutesFrom($filename);
$this->loadViewsFrom(__FILE__ . '/resources/views','cubist_back');
}
+
+
/**
* Register any package services.
*
public function register()
{
-
-
// $this->app->bind('templates', function ($app) {
// return new Template($app);
// });
+++ /dev/null
-<?php
-
-
-namespace Cubist\Backpack\app\Http\Controllers;
-use Backpack\CRUD\CrudTrait;
-
-trait CubistCrud
-{
- use CrudTrait;
-
- public function addField($field, $form = 'both')
- {
- if (isset($field['column_label']) || isset($field['column']) && $field['column'] == true) {
- $column_data = ['name' => $field['name'], 'label' => $field['label'], 'type' => 'text'];
- if (isset($field['column'])) {
- unset($field['column']);
- }
- if (isset($field['column_label'])) {
- $column_data['label'] = $field['column_label'];
- unset($field['column_label']);
- }
- if (isset($field['column_type'])) {
- $column_data['type'] = $field['column_type'];
- unset($column_data['type']);
- }
- $this->crud->addColumn($column_data);
- }
- $this->crud->addField($field, $form);
- }
-}
+++ /dev/null
-<?php
-
-namespace Cubist\Backpack\app\Http\Controllers;
-
-use Backpack\CRUD\app\Http\Controllers\CrudController;
-
-// VALIDATION: change the requests to match your own file names if you need form validation
-use Cubist\Backpack\app\Http\Requests\CubistModelRequest as StoreRequest;
-use Cubist\Backpack\app\Http\Requests\CubistModelRequest as UpdateRequest;
-use Backpack\CRUD\CrudPanel;
-use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
-
-/**
- * Class ModelCrudController
- * @package App\Http\Controllers\Admin
- * @property-read CrudPanel $crud
- */
-class CubistModelCrudController extends CrudController
-{
- use CubistCrud;
- use InstantFields;
-
- public function setup()
- {
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Basic Information
- |--------------------------------------------------------------------------
- */
- $this->crud->setModel('Cubist\Backpack\app\Models\CubistModel');
- $this->crud->setRoute(config('backpack.base.route_prefix') . '/model');
- $this->crud->setEntityNameStrings('model', 'models');
-
-
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Configuration
- |--------------------------------------------------------------------------
- */
-
- $this->addField(['type' => 'text',
- 'name' => 'name',
- 'label' => 'Model table name',
- 'column' => true], 'create');
- $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], 'both');
-
- $this->addField([
- 'name' => 'fields',
- 'type' => 'select2_from_ajax_multiple',
- 'label' => 'Fields definitions',
- 'view_namespace' => 'webfactor::fields',
- 'model' => Entity::class,
- 'entity' => 'modelfield',
- 'attribute' => 'name',
- 'placeholder' => 'Choose',
- 'pagination' => 20, // optional, default: 10
- 'minimum_input_length' => 0,
- 'on_the_fly' => [
- 'entity' => 'modelfield', // e. g. user, contact, company etc...
- 'create' => true,
- 'edit' => true,
- 'delete' => true,
- ]], 'both');
-
- // 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 Cubist\Backpack\app\Http\Controllers;
-
-use Backpack\CRUD\app\Http\Controllers\CrudController;
-
-// VALIDATION: change the requests to match your own file names if you need form validation
-use Cubist\Backpack\app\Http\Requests\CubistModelRequest as StoreRequest;
-use Cubist\Backpack\app\Http\Requests\CubistModelRequest as UpdateRequest;
-use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
-
-
-class CubistModelFieldCrudController extends CrudController
-{
- use CubistCrud;
- use InstantFields;
-
- public function setup()
- {
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Basic Information
- |--------------------------------------------------------------------------
- */
- $this->crud->setModel('Cubist\Backpack\app\Models\CubistModelField');
- $this->crud->setRoute(config('backpack.base.route_prefix') . '/modelfield');
- $this->crud->setEntityNameStrings('modelfield', 'modelfieldss');
-
-
- $this->setAjaxEntity('modelfield');
-
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Configuration
- |--------------------------------------------------------------------------
- */
-
- $this->addField(['type' => 'text',
- 'name' => 'name',
- 'label' => 'Field column name',
- 'column' => true], 'create');
- $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Field label', 'column' => true], 'both');
- $this->addField(['type' => 'table', 'name' => 'attributes', 'label' => 'Attributes'], 'both');
-
- // 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;
- }
-}
-
use Backpack\PageManager\app\Http\Controllers\Admin\PageCrudController;
use Cubist\Backpack\app\Template\TemplateAbstract;
+use Cubist\Backpack\app\Magic\CubistCrud;
use Illuminate\Support\Str;
class CubistPageCrudController extends PageCrudController
+++ /dev/null
-<?php
-
-namespace Cubist\Backpack\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 Cubist\Backpack\app\Magic\Controllers;
+
+
+use Backpack\CRUD\app\Http\Controllers\CrudController;
+use Cubist\Backpack\app\Http\Controllers\CubistCrud;
+use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
+use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
+
+class CubistMagicController extends CrudController
+{
+ use CubistCrud;
+
+ protected $_modelNamespace;
+ protected $_routeURL;
+ protected $_singular;
+ protected $_plural;
+
+ public function setup()
+ {
+ /*
+ |--------------------------------------------------------------------------
+ | CrudPanel Basic Information
+ |--------------------------------------------------------------------------
+ */
+ $this->crud->setModel($this->_modelNamespace);
+ $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
+ $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
+
+
+ /*
+ |--------------------------------------------------------------------------
+ | CrudPanel Configuration
+ |--------------------------------------------------------------------------
+ */
+
+ $this->addField(['type' => 'text',
+ 'name' => 'name',
+ 'label' => 'Model table name',
+ 'column' => true], 'create');
+ $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], 'both');
+
+ $this->addField([
+ 'name' => 'fields',
+ 'type' => 'select2_from_ajax_multiple',
+ 'label' => 'Fields definitions',
+ 'view_namespace' => 'webfactor::fields',
+ 'model' => CubistModelField::class,
+ 'entity' => 'modelfield',
+ 'attribute' => 'name',
+ 'placeholder' => 'Choose',
+ 'pagination' => 20, // optional, default: 10
+ 'minimum_input_length' => 0,
+ 'on_the_fly' => [
+ 'entity' => 'modelfield', // e. g. user, contact, company etc...
+ 'create' => true,
+ 'edit' => true,
+ 'delete' => true,
+ ]], 'both');
+
+ // add asterisk for fields that are required in ModelRequest
+ $this->crud->setRequiredFields(CubistMagicStoreRequest::class, 'create');
+ $this->crud->setRequiredFields(CubistMagicUpdateRequest::class, 'edit');
+ }
+
+ public function store(CubistMagicStoreRequest $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(CubistMagicUpdateRequest $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 Cubist\Backpack\app\Magic;
+
+use Backpack\CRUD\CrudTrait;
+use Cubist\Backpack\app\Magic\Fields\CubistMagicField;
+
+trait CubistCrud
+{
+ use CrudTrait;
+
+ /**
+ * @param $field CubistMagicField
+ */
+ public function addField($field)
+ {
+ if ($field->isDisplayColumn()) {
+ $this->crud->addColumn($field->getColumnData());
+ }
+ $this->crud->addField($field, $field->getCRUDForm());
+ }
+}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic;
+
+
+trait CubistMagicAttribute
+{
+ public function getAttribute($key, $default = null)
+ {
+ if (isset($this->_attributes[$key])) {
+ return $this->_attributes[$key];
+ }
+ return $default;
+ }
+}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Exception;
+
+class CubistMagicField
+{
+ use CubistMagicAttribute;
+ protected $_attributes;
+
+ /**
+ * @param $attributes
+ * @return CubistMagicField
+ * @throws Exception
+ */
+ public static function getInstance($attributes)
+ {
+ if (!isset($attributes['type'])) {
+ throw new Exception('You must specify a field type');
+ }
+ if (!isset($attributes['name'])) {
+ throw new Exception('You must specify a field name');
+ }
+ $class = static::_getClass($attributes['type']);
+ return new $class($attributes);
+ }
+
+ protected static function _getClass($type)
+ {
+ return self::class;
+ }
+
+ public function getDefaultAttributes()
+ {
+ return ['type' => 'text', 'column' => false, 'form' => 'both'];
+ }
+
+ public function __construct($attributes)
+ {
+ $this->_attributes = array_merge($attributes, $this->getDefaultAttributes());
+ $this->init();
+ }
+
+ public function init()
+ {
+
+ }
+
+ /**
+ * @return bool
+ */
+ public function isDisplayColumn()
+ {
+ return !!$this->getAttribute('column');
+ }
+
+ public function getColumnData()
+ {
+ $res = [
+ 'type' => $this->getAttribute('column_type', $this->getAttribute('type')),
+ 'label' => $this->getAttribute('column_label', $this->getAttribute('label'))
+ ];
+
+ return $res;
+ }
+
+ public function getCRUDForm()
+ {
+ return $this->getAttribute('form');
+ }
+
+ public function getDatabaseSchema()
+ {
+
+ }
+}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Models;
+
+use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
+use Cubist\Backpack\app\Magic\Fields\CubistMagicField;
+use Illuminate\Database\Eloquent\Model;
+use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Illuminate\Support\Facades\Route;
+use Backpack\CRUD;
+
+class CubistMagicModelAbstract extends Model
+{
+
+ use CubistMagicAttribute;
+ /**
+ * @var CubistMagicController
+ */
+ protected $_controller = null;
+
+ /**
+ * @var array
+ */
+ protected $_fields = [];
+
+ public function __construct(array $attributes = [])
+ {
+ parent::__construct($attributes);
+ }
+
+ /**
+ * @return CubistMagicController
+ */
+ public function getController(): CubistMagicController
+ {
+ if (null === $this->_controller) {
+ $this->_controller = new CubistMagicController();
+ }
+
+ return $this->_controller;
+ }
+
+ /**
+ * @param $attributes
+ */
+ public function addField($attributes)
+ {
+ /** @var CubistMagicField $field */
+ $field = CubistMagicField::getInstance($attributes);
+ $this->getController()->addField($field);
+
+ $this->_fields[$field->getAttribute('name')] = $field;
+ }
+
+ public function loadRoute()
+ {
+ Route::group([
+ 'prefix' => config('backpack.base.route_prefix', 'admin'),
+ 'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
+ 'namespace' => 'Cubist\Backpack\app\Http\Controllers',
+ ], function () { // custom admin routes
+ CRUD::resource('model', 'CubistModelCrudController');
+ CRUD::resource('model', 'CubistModelCrudController');
+ }); // this should be the absolute last line of this file
+
+
+ }
+}
--- /dev/null
+<?php
+
+
+namespace app\Magic\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class CubistMagicRequest 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 Cubist\Backpack\app\Magic\Requests;
+
+
+use app\Magic\Requests\CubistMagicRequest;
+
+class CubistMagicStoreRequest extends CubistMagicRequest
+{
+
+}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Requests;
+
+
+use app\Magic\Requests\CubistMagicRequest;
+
+class CubistMagicUpdateRequest extends CubistMagicRequest
+{
+
+}
+++ /dev/null
-<?php
-
-namespace Cubist\Backpack\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', 'fields'];
- // protected $hidden = [];
- // protected $dates = [];
-
- /*
- |--------------------------------------------------------------------------
- | FUNCTIONS
- |--------------------------------------------------------------------------
- */
-
- /*
- |--------------------------------------------------------------------------
- | RELATIONS
- |--------------------------------------------------------------------------
- */
-
- /*
- |--------------------------------------------------------------------------
- | SCOPES
- |--------------------------------------------------------------------------
- */
-
- /*
- |--------------------------------------------------------------------------
- | ACCESORS
- |--------------------------------------------------------------------------
- */
-
- /*
- |--------------------------------------------------------------------------
- | MUTATORS
- |--------------------------------------------------------------------------
- */
-}
-
+++ /dev/null
-<?php
-
-
-namespace app\Models;
-
-
-use Backpack\CRUD\CrudTrait;
-
-class CubistModelField
-{
- use CrudTrait;
- protected $table = 'cubist_modelfields';
- protected $fillable = ['name', 'label', 'attributes'];
-}