Files
siakad/resources/views/components/form/checkbox.blade.php
T
2026-10-24 11:45:32 +07:00

20 lines
651 B
PHP

@props(['name', 'label', 'value' => '1', 'checked' => false, 'id' => null])
@php
$id ??= 'check-'.\Illuminate\Support\Str::slug($name);
// Setelah validasi gagal, nilai lama menang atas nilai bawaan (kotak yang tidak dicentang tidak dikirim browser)
$isChecked = request()->hasSession() && session()->hasOldInput() ? (bool) old($name) : (bool) $checked;
@endphp
<label class="check" for="{{ $id }}">
<input
type="checkbox"
id="{{ $id }}"
name="{{ $name }}"
value="{{ $value }}"
@checked($isChecked)
{{ $attributes->class('check__input') }}
>
<span>{{ $label }}</span>
</label>