@php $field['value'] = old_empty_or_null($field['name'], []) ?? ($field['value'] ?? ($field['default'] ?? [])); // make sure the value is always an array, even if stored as JSON in database $field['value'] = is_string($field['value']) ? json_decode($field['value'], true) : $field['value']; if (!empty($field['value'])) { // when repeatable is used to create relations the value returned from those relations // would be collections, contrary to when saved as json in database and casted as array if (is_a($field['value'], \Illuminate\Support\Collection::class)) { $field['value'] = $field['value']->toArray(); } } if ($field['reorder'] !== false) { switch (gettype($field['reorder'])) { case 'string': $field['subfields'] = Arr::prepend($field['subfields'], [ 'name' => $field['reorder'], 'type' => 'hidden', 'attributes' => [ 'data-reorder-input' => true, ], ]); usort($field['value'], fn($a, $b) => $a[$field['reorder']] <=> $b[$field['reorder']]); break; case 'array': $field['subfields'] = Arr::prepend($field['subfields'], $field['reorder']); usort($field['value'], fn($a, $b) => $a[$field['reorder']['name']] <=> $b[$field['reorder']['name']]); break; } } @endphp
@if (!empty($field['value'])) @foreach ($field['value'] as $key => $row) @include($crud->getFirstFieldView('inc.application_fields.item'), [ 'repeatable_row_key' => $key, ]) @endforeach @php // the $row variable still exists. We don't need it anymore the loop is over, and would have impact in the following code. unset($row); @endphp @endif

Ajouter un champ



@push('crud_fields_scripts') @loadOnce('bpFieldApplicationFieldsElement') @endLoadOnce @endpush