@php //in case entity is superNews we want the url friendly super-news $entityWithoutAttribute = $crud->getOnlyRelationEntity($field); $routeEntity = Str::kebab(str_replace('_', '-', $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'; // this field can be used as a pivot selector for n-n relationships $field['is_pivot_select'] = $field['is_pivot_select'] ?? false; $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_empty_or_null($field['name'], []) ?? $field['value'] ?? $field['default'] ?? []; if (!empty($current_value) || is_int($current_value)) { 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; } } @endphp @include('crud::fields.inc.wrapper_start') {{-- To make sure a value gets submitted even if the "select multiple" is empty, we need a hidden input --}} @if($field['multiple'])@endif {{-- 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 --}} {{-- FIELD CSS - will be loaded in the after_styles section --}} {{-- include select2 css --}} @push('crud_fields_styles') @loadOnce('packages/select2/dist/css/select2.min.css') @loadOnce('packages/select2-bootstrap-theme/dist/select2-bootstrap.min.css') @endpush {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') {{-- include select2 js --}} @loadOnce('packages/select2/dist/js/select2.full.min.js') @if (app()->getLocale() !== 'en') @loadOnce('packages/select2/dist/js/i18n/' . str_replace('_', '-', app()->getLocale()) . '.js') @endif @loadOnce('bpFieldInitFetchElement') @endLoadOnce @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}