{{-- relationship --}} @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(); // 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) ->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['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; // this field can be used as a pivot select for n-n relationships $field['is_pivot_select'] = $field['is_pivot_select'] ?? false; $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'] = $field['inline_create']['create_route'] ?? route($field['inline_create']['entity']."-inline-create-save"); //route to modal $field['inline_create']['modal_route'] = $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->getFirstFieldView('relationship.inc.inline_create_button'), ['field' => $field]) @endif {{-- 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') @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') @loadOnce('bpFieldInitFetchOrCreateElement') @if (app()->getLocale() !== 'en') @loadOnce('packages/select2/dist/js/i18n/' . str_replace('_', '-', app()->getLocale()) . '.js') @endif @endLoadOnce @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}