When I click set and then save, ‘John’ is printed instead of ‘Foobar’. I would expect, that the item property is persisted accross clicks. Why is John printed instead?
class LivewireComponent extends Component
{
public $item;
public function mount()
{
$this->item = Item::whereName('John')->firstOrFail();
}
public function set()
{
$this->item->name = "Foobar";
}
public function save()
{
dump($this->item->name);
}
public function render()
{
return view('livewire-component');
}
}
Blade:
<div>
<p>{{ $item->name }}</p>
<button wire:click="set()">Set</button>
<button wire:click="save()">Save</button>
</div>
Code playground: https://laravelplayground.com/#/snippets/9e503a4d-5b7e-4e4e-9323-bbadc54c191b