protected function _getOptions()
{
$modelClass = $this->getAttribute('model');
- /** @var CubistMagicAbstractModel[] $items */
- $items = $modelClass::all();
- $options = [];
+ $inst = new $modelClass();
- $name = $this->getAttribute('attribute');
- foreach ($items as $item) {
- $options[$item->{$item->getPrimaryKey()}] = $item->{$name};
- }
- return $options;
+ return $modelClass::all()->pluck($this->getAttribute('attribute'), $inst->getPrimaryKey());
}
}
{
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]);
+ }
}