ldc-agis/resources/views/bo/partials/inputs/pivot-belongsToMany.blade.php
2023-12-21 13:56:34 +01:00

33 lines
1.4 KiB
PHP

{{--
VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT
$id || The id of the input tag. || string || REQUIRED ||
$name || The name of the input tag. || string || REQUIRED ||
$helper || The helper of the input. || string || REQUIRED ||
$placeholder || The placeholder of the input. || string || REQUIRED ||
$itemsList || Collection of available models. || Collection || REQUIRED ||
$itemLimit || Array of min and max limits. || array<integer> || OPTIONNAL || [0, null]
$model || The model we're creating/editing || Model class || OPTIONNAL || null
--}}
@php
$value = old($name) ?? ($model->{$name} ?? []);
if (is_object($value) and $value instanceof \Illuminate\Support\Collection) {
// * Force beeing an array
$value = $value->all();
}
$data = [
'name' => $name,
'value' => Arr::wrap($value),
'placeholder' => $placeholder,
'itemsList' => $itemsList,
'itemLimit' => $itemLimit ?? null,
'errors' => $errors->getBag('default')->getMessages() ?? [],
];
@endphp
<div class="belongs-to-many-dropdown" data-json='@json($data)'></div>
@include('modules.input-error', [
'inputName' => $name,
'helperId' => "{$id}Help",
'helper' => $helper,
])