namespace Cubist\Backpack\app\Magic\Controllers;
+use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\CrudTrait;
-use Cubist\Backpack\app\Magic\Fields\Field;
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
-use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
-use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
-use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController;
-class CubistMagicController extends NestedModelsCrudController
+class CubistMagicController extends CrudController
{
- use CrudTrait;
+ use CrudTrait,CubistMagicControllerTrait;
protected $_modelNamespace;
protected $_routeURL;
protected $_singular;
protected $_plural;
- protected $_nested = false;
-
- protected $_storeRequest;
- protected $_updateRequest;
-
- public function setup()
- {
- if (!$this->_routeURL) {
- $this->_routeURL = $this->_singular;
- }
- if (!$this->_plural) {
- $this->_plural = $this->_singular . 's';
- }
-
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Basic Information
- |--------------------------------------------------------------------------
- */
- $this->crud->setModel($this->_modelNamespace);
- if ($this->_nested) {
- $this->treeSetup();
- }
- $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
- $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
-
-
- /*
- |--------------------------------------------------------------------------
- | CrudPanel Configuration
- |--------------------------------------------------------------------------
- */
- foreach ($this->getModelInstance()->getFields() as $field) {
- $this->addField($field);
- }
-
- }
-
- public function addField($field)
- {
- if (is_array($field)) {
- $field = Field::getInstance($field);
- }
- /** @var $field Field */
- if ($field->isDisplayColumn()) {
- $this->crud->addColumn($field->getColumnData());
- }
- $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
- }
-
- /**
- * @return CubistMagicModelAbstract
- */
- public function getModelInstance()
- {
- return $this->crud->getModel();
- }
-
-
- 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\Controllers;
+
+use Cubist\Backpack\app\Magic\Fields\Field;
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
+use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
+
+trait CubistMagicControllerTrait
+{
+ public function setup()
+ {
+ if (!$this->_routeURL) {
+ $this->_routeURL = $this->_singular;
+ }
+ if (!$this->_plural) {
+ $this->_plural = $this->_singular . 's';
+ }
+
+ /*
+ |--------------------------------------------------------------------------
+ | CrudPanel Basic Information
+ |--------------------------------------------------------------------------
+ */
+ $this->crud->setModel($this->_modelNamespace);
+ $this->_afterSetModel();
+ $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
+ $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
+
+
+ /*
+ |--------------------------------------------------------------------------
+ | CrudPanel Configuration
+ |--------------------------------------------------------------------------
+ */
+ foreach ($this->getModelInstance()->getFields() as $field) {
+ $this->addField($field);
+ }
+
+ }
+
+ public function addField($field)
+ {
+ if (is_array($field)) {
+ $field = Field::getInstance($field);
+ }
+ /** @var $field Field */
+ if ($field->isDisplayColumn()) {
+ $this->crud->addColumn($field->getColumnData());
+ }
+ $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
+ }
+
+ /**
+ * @return CubistMagicModelAbstract
+ */
+ public function getModelInstance()
+ {
+ return $this->crud->getModel();
+ }
+
+
+ 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\Controllers;
+
+use Backpack\CRUD\CrudTrait;
+use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController;
+
+class CubistNestedMagicController extends NestedModelsCrudController
+{
+ use CrudTrait, CubistMagicControllerTrait;
+
+ protected $_modelNamespace;
+ protected $_routeURL;
+ protected $_singular;
+ protected $_plural;
+
+ public function _afterSetModel(){
+ $this->treeSetup();
+ }
+}
namespace Cubist\Backpack\app\Magic\Models;
+use Backpack\CRUD\CrudTrait;
use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\Util;
use Cviebrock\EloquentSluggable\Sluggable;
{
use CubistMagicAttribute;
use SluggableScopeHelpers;
+ use CrudTrait;
use NestedModelTrait {
replicate as private replicateNodeTrait;
}
'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
'PLURAL' => $this->getOption('plural', ''),
'MODELNAMESPACE' => get_class($this),
- 'NESTED' => $this->nested ? 'true' : 'false',
+ 'EXTENDS' => $this->nested ? 'CubistNestedMagicController' : 'CubistMagicController',
];
$res = file_get_contents($stub);
namespace App\Http\Controllers\Admin;
-use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
+use Cubist\Backpack\app\Magic\Controllers\*;
-class _CONTROLLERCLASS_ extends CubistMagicController
+class _CONTROLLERCLASS_ extends _EXTENDS_
{
protected $_modelNamespace = '_MODELNAMESPACE_';
protected $_routeURL = '_ROUTEURL_';
protected $_singular = '_SINGULAR_';
protected $_plural = '_PLURAL_';
- protected $_nested = _NESTED_;
}