namespace Cubist\Backpack\app\Magic;
use Backpack\CRUD\CrudTrait;
-use Cubist\Backpack\app\Magic\Fields\CubistMagicField;
+use Cubist\Backpack\app\Magic\Fields\Field;
trait CubistCrud
{
use CrudTrait;
/**
- * @param $field CubistMagicField|array
+ * @param $field Field|array
* @throws \Exception
*/
public function addField($field)
{
if (is_array($field)) {
- $field = CubistMagicField::getInstance($field);
+ $field = Field::getInstance($field);
}
- /** @var $field CubistMagicField */
+ /** @var $field Field */
if ($field->isDisplayColumn()) {
$this->crud->addColumn($field->getColumnData());
+++ /dev/null
-<?php
-
-
-namespace Cubist\Backpack\app\Magic\Fields;
-
-use Cubist\Backpack\app\Magic\CubistMagicAttribute;
-use Exception;
-
-class CubistMagicField
-{
- use CubistMagicAttribute;
- protected $_attributes;
- protected $_rules = [];
-
- /**
- * @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', 'rules' => ''];
- }
-
- public function __construct($attributes)
- {
- $this->_attributes = array_merge($this->getDefaultAttributes(), $attributes);
- $this->init();
- }
-
- public function getRules()
- {
- return $this->getAttribute('rules', '');
- }
-
- public function getDefinition()
- {
- return $this->_attributes;
- }
-
- 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\Fields;
+
+use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Exception;
+
+class Field
+{
+ use CubistMagicAttribute;
+ protected $_attributes;
+ protected $_rules = [];
+
+ /**
+ * @param $attributes
+ * @return Field
+ * @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', 'rules' => ''];
+ }
+
+ public function __construct($attributes)
+ {
+ $this->_attributes = array_merge($this->getDefaultAttributes(), $attributes);
+ $this->init();
+ }
+
+ public function getRules()
+ {
+ return $this->getAttribute('rules', '');
+ }
+
+ public function getDefinition()
+ {
+ return $this->_attributes;
+ }
+
+ 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()
+ {
+
+ }
+}
namespace Cubist\Backpack\app\Magic\Models;
use Backpack\CRUD\CrudTrait;
-use Cubist\Backpack\app\Magic\Fields\CubistMagicField;
+use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\Util;
use Illuminate\Database\Eloquent\Model;
use Cubist\Backpack\app\Magic\CubistMagicAttribute;
use CrudTrait;
/**
- * @var CubistMagicField[]
+ * @var Field[]
*/
protected $_fields = [];
*/
public function addField($attributes)
{
- /** @var CubistMagicField $field */
- $field = CubistMagicField::getInstance($attributes);
+ /** @var Field $field */
+ $field = Field::getInstance($attributes);
$name = $field->getAttribute('name');
$this->_fields[$name] = $field;
$this->fillable[] = $name;
<?php
-
namespace Cubist\Backpack\app\Magic\Requests;
-
use app\Magic\Requests\CubistMagicRequest;
class CubistMagicStoreRequest extends CubistMagicRequest