class Model extends Field
{
protected static $_options = [];
+ protected $___options = null;
public function getDefaultAttributes()
{
public function _getOptions()
{
- return $this->pluck($this->getAttribute('attribute'));
+ if (null === $this->___options) {
+ $this->___options = $this->pluck($this->getAttribute('attribute'));
+ }
+ return $this->___options;
}
public function pluck($attr)
protected $_options = [];
protected $_options_aliases = [];
protected $_filterType = 'dropdown';
- protected $_ajax = false;
+ protected $_ajax = true;
public function getDefaultAttributes()
{
$this->setAttribute('allows_null', false);
}
if ($this->getAttribute('ajax', false)) {
- $data = [];
- foreach ($this->getOptions() as $k => $v) {
- $data[$k] = ['t' => $v, 'n' => self::normalize($v)];
- }
- $hash = hash('sha256', print_r($data, true));
- $name = $hash . '.json';
- $dir = \Cubist\Util\Files\Files::mkdir(storage_path('select2'));
- $file = $dir . '/' . $name;
- if (!file_exists($file)) {
- file_put_contents($file, json_encode($data));
- }
- $this->setAttribute('ajax', $hash);
+ $this->setAttribute('ajax', self::hashOptions($this->getOptions()));
+ }
+ }
+
+ public static function hashOptions($options){
+ $data = [];
+ foreach ($options as $k => $v) {
+ $data[$k] = ['t' => $v, 'n' => self::normalize($v)];
+ }
+ $hash = hash('sha256', print_r($data, true));
+ $name = $hash . '.json';
+ $dir = \Cubist\Util\Files\Files::mkdir(storage_path('select2'));
+ $file = $dir . '/' . $name;
+ if (!file_exists($file)) {
+ file_put_contents($file, json_encode($data));
}
+ return $hash;
}
// public function getDatabaseLength()
protected $_order = false;
protected $_allows_null = false;
+ protected $_ajax = true;
+
public function getDefaultAttributes()
{
$field = $this;
return array_merge(parent::getDefaultAttributes(), [
+ 'ajax' => $this->_ajax,
'order' => $this->_order,
'allows_null' => $this->_allows_null,
'searchLogic' => function ($query, $column, $searchTerm) use ($field) {
protected function _preGetDefinition()
{
parent::_preGetDefinition();
- $this->setAttribute('options', $this->_getOptions());
+ $o=$this->_getOptions();
+ $this->setAttribute('options', $o);
+ if ($this->getAttribute('ajax', false)) {
+ $this->setAttribute('ajax', SelectFromArray::hashOptions($o));
+ }
+
}
public function _postSetAttributes()
$this->setAttribute('cast', 'array');
}
+
parent::_postSetAttributes();
}
+
protected function _getAttributesAliases()
{
return array_merge(parent::_getAttributesAliases(), [