}
protected function _getOptions()
+ {
+ return $this->pluck($this->getAttribute('attribute'));
+ }
+
+ public function pluck($attr)
{
$modelClass = $this->getAttribute('optionsmodel');
- $attr = $this->getAttribute('attribute');
$cacheKey = '_getOption_Model_' . $modelClass . '-' . $attr;
-
if (isset(static::$_options[$cacheKey])) {
return static::$_options[$cacheKey];
}
-
start_measure($cacheKey, 'Get options for model ' . $modelClass . ' / ' . $attr);
- $tag='model_' . $modelClass;
+ $tag = 'model_' . $modelClass;
static::$_options[$cacheKey] = cache()->tags([$tag])->remember($cacheKey, 86400, function () use ($modelClass, $attr) {
/** @var \Illuminate\Database\Eloquent\Model $inst */
$inst = new $modelClass();
$options = $modelClass::all();
-
return $options->pluck($attr, $inst->getKeyName())->toArray();
});
stop_measure($cacheKey);
namespace Cubist\Backpack\app\Magic\Fields;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+
class ModelAttribute extends StaticValue
{
public function filterValue($value)
{
- $a = $this->getAttribute('attributes');
+ $a = $this->getAttribute('attribute');
+ $e = explode('.', $a);
+
+ $i = $this->getModelInstance();
+ $v0 = $i->getAttribute($e[0]);
+ if (count($e) === 1) {
+ return $v0;
+ }
+
+ if ($i instanceof CubistMagicAbstractModel) {
+ $f = $i->getField($e[0]);
+ if ($f instanceof Model) {
+ return $f->pluck($e[1])[$v0];
+ }
+ }
}
}