{{-- select2_nested --}} {{-- Thanks to Erwan Pianezza - https://github.com/breizhwave--}} {{-- This field assumes you have a nested set Eloquent model, using: --}} {{-- 1. children() as a properly defined relationship --}} {{-- 2. depth, lft attributes --}} @php $current_value = old_empty_or_null($field['name'], '') ?? $field['value'] ?? $field['default'] ?? ''; if (!empty($current_value)) { $current_value = is_object($current_value) ? $current_value->getKey() : $current_value; } if (!function_exists('echoSelect2NestedEntry')) { function echoSelect2NestedEntry($entry, $field, $current_value) { if ($current_value == $entry->getKey()) { $selected = ' selected '; } else { $selected = ''; } echo '"; } } if (!function_exists('echoSelect2NestedChildren')) { function echoSelect2NestedChildren($entity, $field, $current_value) { foreach ($entity->children()->get() as $entry) { echoSelect2NestedEntry($entry, $field, $current_value); echoSelect2NestedChildren($entry, $field, $current_value); } } } $entity_model = $crud->getRelationModel($field['entity'], -1); $field['allows_null'] = $field['allows_null'] ?? $entity_model::isColumnNullable($field['name']); $field['placeholder'] = $field['placeholder'] ?? trans('backpack::crud.select_entry'); @endphp @include('crud::fields.inc.wrapper_start') @include('crud::fields.inc.translatable_icon') {{-- HINT --}} @if (isset($field['hint']))
{!! $field['hint'] !!}
@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} {{-- Extra CSS and JS for this particular field --}} {{-- FIELD CSS - will be loaded in the after_styles section --}} @push('crud_fields_styles') {{-- include select2 css --}} @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('bpFieldInitSelect2NestedElement') @endLoadOnce @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}