/** * Handle the options. * * @param RelationshipFieldType $fieldType * @return array */ public function handle(RelationshipFieldType $fieldType) { $model = $fieldType->getRelatedModel(); if (!$model instanceof EloquentModel) { return []; } $query = $model->newQuery(); $title = array_get($fieldType->getConfig(), 'title'); $key = array_get($fieldType->getConfig(), 'key'); return array_filter([null => $fieldType->getPlaceholder()] + $query->get()->lists($title ?: $model->getTitleName(), $key ?: $model->getKeyName())); }
/** * Handle the options. * * @param RelationshipFieldType $fieldType * @return array */ public function handle(RelationshipFieldType $fieldType) { $model = $fieldType->getRelatedModel(); $query = $model->newQuery(); $fieldType->setOptions($query->get()->lists($model->getTitleName(), $model->getKeyName())->all()); }