Add old tag for components, for values that are nested in an array. Enable LeenooksCarbon to accept a string date when setting.

This commit is contained in:
Deon George 2024-07-24 14:08:04 +10:00
parent 3a12ec005e
commit f393813311
10 changed files with 16 additions and 15 deletions

View File

@ -10,7 +10,7 @@
@endif()
{{ $slot }}
<span class="invalid-feedback" role="alert">
@error($name)
@error($old ?? $name)
{{ $message }}
@elseif(isset($feedback))
{{ $feedback }}

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="date" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
<input type="date" class="form-control {{ $classes ?? ''}}@error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($old ?? $name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="email" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
<input type="email" class="form-control {{ $classes ?? ''}}@error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($old ?? $name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,5 +1,5 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="file" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @readonly(isset($readonly)) @required(isset($required))>
<input type="file" class="form-control {{ $classes ?? ''}}@error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>
{{ $slot }}

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="password" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
<input type="password" class="form-control {{ $classes ?? ''}}@error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($old ?? $name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,6 +1,6 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="hidden" id="{{ $name }}_disabled" name="{{ $name }}" value="" disabled>
<select class="form-control @error($name) is-invalid @enderror" id="{{ $id }}" name="{{ $name }}">
<select class="form-control @error($old ?? $name) is-invalid @enderror" id="{{ $id }}" name="{{ $name }}">
@if(isset($addvalues) && $addvalues)
<option id="new"></option>
@endif
@ -8,14 +8,14 @@
@empty($groupby)
@foreach($options as $option)
@continue(! Arr::get($option,'value'))
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($name,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($old ?? $name,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
@endforeach
@else
@foreach($options->groupBy($groupby) as $group)
<optgroup label="{{ $groupby == 'active' ? (Arr::get($group->first(),$groupby) ? 'Active' : 'Not Active') : Arr::get($group->first(),$groupby) }}">
@foreach($group as $option)
@continue(! Arr::get($option,'value'))
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($old,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($old ?? $name,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
@endforeach
</optgroup>
@endforeach

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="text" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
<input type="text" class="form-control {{ $classes ?? ''}}@error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($old ?? $name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<textarea class="form-control {{ $classes ?? ''}} @error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @isset($placeholder)placeholder="{{ $placeholder }}"@endisset>{{ old($name,$value ?? '') }}</textarea>
<textarea class="form-control {{ $classes ?? ''}} @error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @isset($placeholder)placeholder="{{ $placeholder }}"@endisset>{{ old($old ?? $name,$value ?? '') }}</textarea>
</x-leenooks::form.base>

View File

@ -1,7 +1,7 @@
<div class="form-group">
<div class="input-group has-validation">
<div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
<input type="checkbox" class="custom-control-input @error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @checked(old($name,$value ?? ''))>
<input type="checkbox" class="custom-control-input @error($old ?? $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @checked(old($old ?? $name,$value ?? ''))>
@if(isset($label))
<label class="custom-control-label" for="{{ $id ?? $name }}">{{ $label }}</label>
@endif

View File

@ -4,6 +4,7 @@ namespace Leenooks\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
use Leenooks\Carbon;
class LeenooksCarbon implements CastsAttributes
{
@ -12,9 +13,9 @@ class LeenooksCarbon implements CastsAttributes
*
* @param array<string, mixed> $attributes
*/
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
public function get(Model $model, string $key, mixed $value, array $attributes): Carbon
{
return \Leenooks\Carbon::create($value);
return Carbon::create($value);
}
/**
@ -22,8 +23,8 @@ class LeenooksCarbon implements CastsAttributes
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
public function set(Model $model, string $key, mixed $value, array $attributes): string
{
return $value->format('Y-m-d H:i:s');
return ($value instanceof Carbon ? $value : $this->get($model,$key,$value,$attributes))->format('Y-m-d H:i:s');
}
}