{{-- select2 multiple --}} @php if (!isset($field['options'])) { $field['options'] = $field['model']::all(); } else { $field['options'] = call_user_func($field['options'], $field['model']::query()); } //build option keys array to use with Select All in javascript. $model_instance = new $field['model']; $options_ids_array = $field['options']->pluck($model_instance->getKeyName())->toArray(); $field['multiple'] = true; $field['allows_null'] = $field['allows_null'] ?? $crud->model::isColumnNullable($field['name']); $field['placeholder'] = $field['placeholder'] ?? trans('backpack::crud.select_entries'); $field['value'] = old_empty_or_null($field['name'], collect()) ?? $field['value'] ?? $field['default'] ?? collect(); // when value is returned from crud panel it will be a collection, when returns from `old()` is already an array if (is_a($field['value'], \Illuminate\Support\Collection::class)) { $field['value'] = $field['value']->pluck($model_instance->getKeyName())->toArray(); } @endphp @include('crud::fields.inc.wrapper_start') @include('crud::fields.inc.translatable_icon') {{-- To make sure a value gets submitted even if the "select multiple" is empty, we need a hidden input --}} @if(isset($field['select_all']) && $field['select_all']) {{ trans('backpack::crud.select_all') }} {{ trans('backpack::crud.clear') }} @endif {{-- 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('bpFieldInitSelect2MultipleElement') @endLoadOnce @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}