What seems to be the problem:
When casting to a date property and error occurs when trying to addYear(). The exact message states: "Call to a member function addYear() on string"
Steps to Reproduce:
Have a input type of date, change the date field and the error is thrown.
Are you using the latest version of Livewire:
Yes
Do you have any screenshots or code examples:
public $endsOnDate;
public $reminder;
protected $casts = [
'endsOnDate' => 'date:Y-m-d',
'reminder' => 'date:Y-m-d',
];
public function mount()
{
$this->reminder = now();
$this->endsOnDate = now()->addYear();
}
public function updatedReminder()
{
$this->endsOnDate = $this->reminder->addYear();
}
public function render()
{
return view('livewire.testing');
}
The view looks like this:
<div>
<input wire:model="reminder" type="date" />
<input wire:model="endsOnDate" type="date" />
</div>
The end goal is to add a year to the endsOnDate when the reminder date is updated. How can I do this?