@php //in case entity is superNews we want the url friendly super-news $entityWithoutAttribute = $crud->getOnlyRelationEntity($field); $routeEntity = Str::kebab($entityWithoutAttribute); $connected_entity = new $field['model']; $connected_entity_key_name = $connected_entity->getKeyName(); // we need to re-ensure field type here because relationship is a `switchboard` and not actually // a crud field like this one. $field['type'] = 'fetch'; $field['multiple'] = $field['multiple'] ?? $crud->guessIfFieldHasMultipleFromRelationType($field['relation_type']); $field['data_source'] = $field['data_source'] ?? url($crud->route.'/fetch/'.$routeEntity); $field['attribute'] = $field['attribute'] ?? $connected_entity->identifiableAttribute(); $field['placeholder'] = $field['placeholder'] ?? ($field['multiple'] ? trans('backpack::crud.select_entries') : trans('backpack::crud.select_entry')); $field['include_all_form_fields'] = $field['include_all_form_fields'] ?? true; // Note: isColumnNullable returns true if column is nullable in database, also true if column does not exist. $field['allows_null'] = $field['allows_null'] ?? $crud->model::isColumnNullable($field['name']); // this is the time we wait before send the query to the search endpoint, after the user as stopped typing. $field['delay'] = $field['delay'] ?? 500; // make sure the $field['value'] takes the proper value // and format it to JSON, so that select2 can parse it $current_value = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? ''; if ($current_value != false) { switch (gettype($current_value)) { case 'array': $current_value = $connected_entity ->whereIn($connected_entity_key_name, $current_value) ->get() ->pluck($field['attribute'], $connected_entity_key_name); break; case 'object': if (is_subclass_of(get_class($current_value), 'Illuminate\Database\Eloquent\Model') ) { $current_value = [$current_value->{$connected_entity_key_name} => $current_value->{$field['attribute']}]; }else{ if(! $current_value->isEmpty()) { $current_value = $current_value ->pluck($field['attribute'], $connected_entity_key_name) ->toArray(); } } break; default: $current_value = $connected_entity ->where($connected_entity_key_name, $current_value) ->get() ->pluck($field['attribute'], $connected_entity_key_name); break; } } $field['value'] = json_encode($current_value); @endphp @include('crud::fields.inc.wrapper_start') {{-- HINT --}} @if (isset($field['hint']))

{!! $field['hint'] !!}

@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} {{-- Extra CSS and JS for this particular field --}} {{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}} @if ($crud->fieldTypeNotLoaded($field)) @php $crud->markFieldTypeAsLoaded($field); @endphp {{-- FIELD CSS - will be loaded in the after_styles section --}} @push('crud_fields_styles') @endpush {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') @if (app()->getLocale() !== 'en') @endif @endpush @push('crud_fields_scripts') @endpush @endif {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}