From f393813311b912f77e4a7082498ed7511482b531 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 24 Jul 2024 14:08:04 +1000 Subject: [PATCH] Add old tag for components, for values that are nested in an array. Enable LeenooksCarbon to accept a string date when setting. --- resources/components/form/base.blade.php | 2 +- resources/components/form/date.blade.php | 2 +- resources/components/form/email.blade.php | 2 +- resources/components/form/file.blade.php | 2 +- resources/components/form/password.blade.php | 2 +- resources/components/form/select.blade.php | 6 +++--- resources/components/form/text.blade.php | 2 +- resources/components/form/textarea.blade.php | 2 +- resources/components/form/toggle.blade.php | 2 +- src/Casts/LeenooksCarbon.php | 9 +++++---- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/resources/components/form/base.blade.php b/resources/components/form/base.blade.php index 8c6ef54..c854c6e 100644 --- a/resources/components/form/base.blade.php +++ b/resources/components/form/base.blade.php @@ -10,7 +10,7 @@ @endif() {{ $slot }} - @error($name) + @error($old ?? $name) {{ $message }} @elseif(isset($feedback)) {{ $feedback }} diff --git a/resources/components/form/date.blade.php b/resources/components/form/date.blade.php index a49d23c..b5342e2 100644 --- a/resources/components/form/date.blade.php +++ b/resources/components/form/date.blade.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/resources/components/form/email.blade.php b/resources/components/form/email.blade.php index 6086442..bfe4f0d 100644 --- a/resources/components/form/email.blade.php +++ b/resources/components/form/email.blade.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/resources/components/form/file.blade.php b/resources/components/form/file.blade.php index 764dbb5..f850ef7 100644 --- a/resources/components/form/file.blade.php +++ b/resources/components/form/file.blade.php @@ -1,5 +1,5 @@ - + {{ $slot }} diff --git a/resources/components/form/password.blade.php b/resources/components/form/password.blade.php index fcf3400..032cb55 100644 --- a/resources/components/form/password.blade.php +++ b/resources/components/form/password.blade.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/resources/components/form/select.blade.php b/resources/components/form/select.blade.php index 67a6658..a2b7caa 100644 --- a/resources/components/form/select.blade.php +++ b/resources/components/form/select.blade.php @@ -1,6 +1,6 @@ - @if(isset($addvalues) && $addvalues) @endif @@ -8,14 +8,14 @@ @empty($groupby) @foreach($options as $option) @continue(! Arr::get($option,'value')) - + @endforeach @else @foreach($options->groupBy($groupby) as $group) @foreach($group as $option) @continue(! Arr::get($option,'value')) - + @endforeach @endforeach diff --git a/resources/components/form/text.blade.php b/resources/components/form/text.blade.php index d4a07f7..2782034 100644 --- a/resources/components/form/text.blade.php +++ b/resources/components/form/text.blade.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/resources/components/form/textarea.blade.php b/resources/components/form/textarea.blade.php index a3e1086..81d85ab 100644 --- a/resources/components/form/textarea.blade.php +++ b/resources/components/form/textarea.blade.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/resources/components/form/toggle.blade.php b/resources/components/form/toggle.blade.php index 387acc0..c9c7c3b 100644 --- a/resources/components/form/toggle.blade.php +++ b/resources/components/form/toggle.blade.php @@ -1,7 +1,7 @@
- + @if(isset($label)) @endif diff --git a/src/Casts/LeenooksCarbon.php b/src/Casts/LeenooksCarbon.php index fb8de5a..d175b32 100644 --- a/src/Casts/LeenooksCarbon.php +++ b/src/Casts/LeenooksCarbon.php @@ -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 $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 $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'); } }