Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Fixed Date Component #107

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- issue with date field on invalid date format.

## [0.12.5] - 2020-07-26
### Fixed
- further combobox errors.
Expand Down
10 changes: 8 additions & 2 deletions src/View/Components/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GeneaLabs\LaravelCasts\View\Components;

use Throwable;
use Illuminate\Support\Carbon;

class Date extends BaseComponent
Expand All @@ -20,10 +21,15 @@ public function __construct(

if ($this->value) {
if (! $this->value instanceof Carbon) {
$this->value = (new Carbon)->parse($this->value);
try {
$this->value = (new Carbon)->make($this->value);
} catch (Throwable) {
$this->value = null;
}
}

$this->value = $this->value->format("Y-m-d");
$this->value = $this->value
?->format("Y-m-d");
}
}
}