@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(); // 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'])) ?? old($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) ->toArray(); 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) ->toArray(); break; } } $field['value'] = json_encode($current_value); $field['data_source'] = $field['data_source'] ?? url($crud->route.'/fetch/'.$routeEntity); $field['include_all_form_fields'] = $field['include_all_form_fields'] ?? true; // 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; $activeInlineCreate = !empty($field['inline_create']) ? true : false; if($activeInlineCreate) { //we check if this field is not beeing requested in some InlineCreate operation. //this variable is setup by InlineCreate modal when loading the fields. if(!isset($inlineCreate)) { //by default, when creating an entity we want it to be selected/added to selection. $field['inline_create']['force_select'] = $field['inline_create']['force_select'] ?? true; $field['inline_create']['modal_class'] = $field['inline_create']['modal_class'] ?? 'modal-dialog'; //if user don't specify a different entity in inline_create we assume it's the same from $field['entity'] kebabed $field['inline_create']['entity'] = $field['inline_create']['entity'] ?? $routeEntity; //route to create a new entity $field['inline_create']['create_route'] = route($field['inline_create']['entity']."-inline-create-save"); //route to modal $field['inline_create']['modal_route'] = route($field['inline_create']['entity']."-inline-create"); //include main form fields in the request when asking for modal data, //allow the developer to modify the inline create modal //based on some field on the main form $field['inline_create']['include_main_form_fields'] = $field['inline_create']['include_main_form_fields'] ?? false; if(!is_bool($field['inline_create']['include_main_form_fields'])) { if(is_array($field['inline_create']['include_main_form_fields'])) { $field['inline_create']['include_main_form_fields'] = json_encode($field['inline_create']['include_main_form_fields']); }else{ //it is a string or treat it like $arrayed_field = array($field['inline_create']['include_main_form_fields']); $field['inline_create']['include_main_form_fields'] = json_encode($arrayed_field); } } } } @endphp @include('crud::fields.inc.wrapper_start') @include('crud::fields.inc.translatable_icon') @if($activeInlineCreate) @include('crud::fields.relationship.inline_create_button', ['field' => $field]) @endif {{-- HINT --}} @if (isset($field['hint']))

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

@endif @include('crud::fields.inc.wrapper_end') @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 @endif {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}