use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Backpack\app\Magic\Requests\CubistMagicRequest;
use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
return $this->crud->getModel();
}
+ /**
+ * @param CubistMagicRequest $request
+ * @return CubistMagicRequest
+ */
+ protected function _prepareCRUDData(CubistMagicRequest $request)
+ {
+ foreach ($request->all() as $field => $content) {
+ if (is_array($content)) {
+ $request->request->set($field, json_encode($content));
+ }
+ }
+ return $request;
+ }
+ /**
+ * @param CubistMagicStoreRequest $request
+ * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Http\RedirectResponse
+ */
public function store(CubistMagicStoreRequest $request)
{
+ $request = $this->_prepareCRUDData($request);
+
// your additional operations before save here
$redirect_location = parent::storeCrud($request);
// your additional operations after save here
return $redirect_location;
}
+ /**
+ * @param CubistMagicUpdateRequest $request
+ * @return \Illuminate\Http\RedirectResponse
+ */
public function update(CubistMagicUpdateRequest $request)
{
+ $request = $this->_prepareCRUDData($request);
+
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
$this->_modelInstance = $modelInstance;
return $this;
}
-
+
public function getDatabaseType()
{
public function __construct($attributes)
{
+ $aliases = ['multiple' => 'allows_multiple'];
+ foreach ($aliases as $alias => $real) {
+ if (isset($attributes[$alias])) {
+ $attributes[$real] = $attributes[$alias];
+ unset($attributes[$alias]);
+ }
+ }
+
$this->_attributes = array_merge($this->getDefaultAttributes(), $attributes);
$this->_postSetAttributes();
$this->init();
{
protected $_adminType = 'select2_from_array';
protected $_columnType = 'select_from_array';
- protected $_databaseType = 'text';
+ protected $_databaseType = 'string';
protected $_multiple = false;
+ protected $_order = false;
+
+ public function getDefaultAttributes()
+ {
+ return array_merge(parent::getDefaultAttributes(), ['order' => $this->_order]);
+ }
public function _postSetAttributes()
{
- parent::_postSetAttributes();
$this->setAttribute('options', $this->_getOptions());
+
+ if ($this->getAttribute('allows_multiple') && $this->getAttribute('order')) {
+ $this->setAttribute('type', 'select_and_order');
+ }
+
+ if ($this->getAttribute('allows_multiple')) {
+ $this->setAttribute('cast', 'json');
+ }
+
+ parent::_postSetAttributes();
}
}
+++ /dev/null
-<?php
-
-
-namespace Cubist\Backpack\app\Magic\Fields;
-
-
-class SelectFromModelMultiple extends SelectFromModel
-{
- protected $_multiple = true;
- protected $_cast = 'array';
- protected $_order = false;
-
- public function _postSetAttributes()
- {
- parent::_postSetAttributes(); // TODO: Change the autogenerated stub
- if ($this->getAttribute('order')) {
- $this->_adminType = 'select_and_order';
- }
- }
-
- public function getDefaultAttributes()
- {
- return array_merge(parent::getDefaultAttributes(), ['order' => $this->_order]);
- }
-}