/**
  * Handle the options.
  *
  * @param MultipleFieldType $fieldType
  * @return array
  * @throws \Exception
  */
 public function handle(MultipleFieldType $fieldType)
 {
     $model = $fieldType->getRelatedModel();
     if (!$model instanceof EloquentModel) {
         return [];
     }
     return $model->all()->lists(array_get($fieldType->getConfig(), 'title', $model->getTitleName()), $model->getKeyName());
 }
 /**
  * Handle the options.
  *
  * @param MultipleFieldType $fieldType
  * @return array
  */
 public function handle(MultipleFieldType $fieldType)
 {
     $model = $fieldType->getRelatedModel();
     /* @var Builder $query */
     $query = $model->newQuery();
     /* @var EloquentCollection $results */
     $results = $query->get();
     $fieldType->setOptions($results->lists($model->getTitleName(), $model->getKeyName())->all());
 }
 /**
  * Handle the command.
  *
  * @param MultipleFieldType $fieldType
  * @param AddonCollection   $addons
  * @param Container         $container
  * @param Repository        $config
  * @return array
  */
 public function handle(MultipleFieldType $fieldType, AddonCollection $addons, Container $container, Repository $config)
 {
     $definition = [];
     $key = 'multiple.lookup.' . get_class($container->make($this->table->config('related')));
     /* @var Addon $addon */
     foreach ($addons->withConfig($key) as $addon) {
         $definition = $config->get($addon->getNamespace($key));
     }
     $definition = $config->get($fieldType->getNamespace($key), $definition);
     return $definition;
 }
 /**
  * Return a simple lists string.
  *
  * @return null|string
  */
 public function lists($column = null)
 {
     /* @var Relation $value */
     $value = $this->object->getValue();
     $related = $this->object->getRelatedModel();
     /* @var EloquentCollection $relations */
     if ($relations = $value->get()) {
         return implode(', ', $relations->lists($column ?: $related->getTitleName()));
     }
     return null;
 }
 /**
  * Handle the command.
  *
  * @param Container $container
  */
 public function handle(Container $container)
 {
     $handler = array_get($this->fieldType->getConfig(), 'handler');
     if (!class_exists($handler) && !str_contains($handler, '@')) {
         $handler = array_get($this->fieldType->getHandlers(), $handler);
     }
     if (is_string($handler) && !str_contains($handler, '@')) {
         $handler .= '@handle';
     }
     $container->call($handler, ['fieldType' => $this->fieldType]);
 }
 /**
  * @param Container         $container
  * @param MultipleFieldType $fieldType
  * @param                   $key
  */
 public function json(Container $container, MultipleFieldType $fieldType, $key)
 {
     /* @var Collection $config */
     $config = $this->dispatch(new GetConfiguration($key));
     $fieldType->mergeConfig($config->all());
     /* @var EloquentModel $model */
     $model = $container->make($config->get('related'));
     $data = [];
     /* @var EntryInterface $item */
     foreach ($model->all() as $item) {
         $data[] = (object) ['id' => $item->getId(), 'text' => $item->getTitle()];
     }
     return $this->response->json($data);
 }
 /**
  * Get the value.
  *
  * @return mixed
  */
 public function get()
 {
     return $this->fieldType->getRelation();
 }