You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering a date format compatibility issue between my Laravel application and the component when using Livewire.
Description of the Issue:
In my Laravel Livewire component, I have an endDate property which needs to be selected using a <x-datetime-picker>.
When I use the wire:model.defer="normalPicker" or wire:model.defer="customFormat" as per the component's documentation, the datetime picker works correctly. However, this setup conflicts with the date format used in my Laravel application.
The preloaded endDate in my Laravel app uses a different date format, and due to this mismatch, the datetime picker does not display the correct initial date.
Relevant Code:
Laravel Model (daysLeft() function):
protected function daysLeft(): Attribute
{
return Attribute::make(
get: function () {
$endDate = new Carbon(new DateTime($this->end_date));
if ($endDate->isFuture()) {
return $endDate->diffForHumans();
} else {
return -1;
}
}
);
}
Livewire Component:
public $endDate;
public function mount() {
// Assume $this->campaign->end_date is in a specific format
$this->endDate = $this->campaign->end_date;
}
// ... other methods and properties
Blade Template: <x-datetime-picker label="End Date" placeholder="Campaign end date" wire:model.defer="endDate" class="mb-4" />
I have tried using normalPicker and customFormat configurations, which work but conflict with my Laravel app's date format.
How can I align the date format between the component and my Laravel application's endDate format?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am encountering a date format compatibility issue between my Laravel application and the component when using Livewire.
Description of the Issue:
<x-datetime-picker>
.wire:model.defer="normalPicker"
orwire:model.defer="customFormat"
as per the component's documentation, the datetime picker works correctly. However, this setup conflicts with the date format used in my Laravel application.endDate
in my Laravel app uses a different date format, and due to this mismatch, the datetime picker does not display the correct initial date.Relevant Code:
Laravel Model (daysLeft() function):
Livewire Component:
Blade Template:
<x-datetime-picker label="End Date" placeholder="Campaign end date" wire:model.defer="endDate" class="mb-4" />
I have tried using normalPicker and customFormat configurations, which work but conflict with my Laravel app's date format.
How can I align the date format between the component and my Laravel application's endDate format?
Beta Was this translation helpful? Give feedback.
All reactions