From a16d821c30b76727ea71ed89ac40058404dc679f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 24 May 2019 12:03:01 +0200 Subject: [PATCH] #2783 --- src/app/Magic/Controllers/CubistMagicController.php | 9 ++++----- src/app/Magic/Fields/CubistMagicField.php | 8 +++++++- src/app/Magic/Models/CubistMagicModelAbstract.php | 6 +++++- src/app/Magic/Requests/CubistMagicRequest.php | 10 ++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 3241d58..9e6d665 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -18,6 +18,9 @@ class CubistMagicController extends CrudController protected $_plural; protected $_fields = []; + protected $_storeRequest; + protected $_updateRequest; + public function setup() { if (!$this->_routeURL) { @@ -46,13 +49,9 @@ class CubistMagicController extends CrudController foreach ($this->_fields as $field) { $this->addField($field); } - - - // 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 diff --git a/src/app/Magic/Fields/CubistMagicField.php b/src/app/Magic/Fields/CubistMagicField.php index 8a81d6e..49b1c57 100644 --- a/src/app/Magic/Fields/CubistMagicField.php +++ b/src/app/Magic/Fields/CubistMagicField.php @@ -10,6 +10,7 @@ class CubistMagicField { use CubistMagicAttribute; protected $_attributes; + protected $_rules = []; /** * @param $attributes @@ -35,7 +36,7 @@ class CubistMagicField public function getDefaultAttributes() { - return ['type' => 'text', 'column' => false, 'form' => 'both']; + return ['type' => 'text', 'column' => false, 'form' => 'both', 'rules' => '']; } public function __construct($attributes) @@ -44,6 +45,11 @@ class CubistMagicField $this->init(); } + public function getRules() + { + return $this->getAttribute('rules', ''); + } + public function getDefinition() { return $this->_attributes; diff --git a/src/app/Magic/Models/CubistMagicModelAbstract.php b/src/app/Magic/Models/CubistMagicModelAbstract.php index a3bbeb4..291a4d5 100644 --- a/src/app/Magic/Models/CubistMagicModelAbstract.php +++ b/src/app/Magic/Models/CubistMagicModelAbstract.php @@ -3,6 +3,7 @@ namespace Cubist\Backpack\app\Magic\Models; +use Backpack\CRUD\CrudTrait; use Cubist\Backpack\app\Magic\Fields\CubistMagicField; use Cubist\Backpack\app\Magic\Util; use Illuminate\Database\Eloquent\Model; @@ -13,6 +14,7 @@ class CubistMagicModelAbstract extends Model { use CubistMagicAttribute; + use CrudTrait; /** * @var CubistMagicField[] @@ -50,7 +52,9 @@ class CubistMagicModelAbstract extends Model { /** @var CubistMagicField $field */ $field = CubistMagicField::getInstance($attributes); - $this->_fields[$field->getAttribute('name')] = $field; + $name = $field->getAttribute('name'); + $this->_fields[$name] = $field; + $this->fillable[] = $name; } public function generateCode() diff --git a/src/app/Magic/Requests/CubistMagicRequest.php b/src/app/Magic/Requests/CubistMagicRequest.php index d5c64d4..fe8cc50 100644 --- a/src/app/Magic/Requests/CubistMagicRequest.php +++ b/src/app/Magic/Requests/CubistMagicRequest.php @@ -7,6 +7,15 @@ use Illuminate\Foundation\Http\FormRequest; class CubistMagicRequest extends FormRequest { + /** + * CubistMagicRequest constructor. + */ + public function __construct($controller, $operation) + { + $this->__construct(); + } + + /** * Determine if the user is authorized to make this request. * @@ -26,6 +35,7 @@ class CubistMagicRequest extends FormRequest */ public function rules() { + return [ // 'name' => 'required|min:5|max:255' ]; -- 2.39.5