Function AutoInvoke
Hello! I'm trying to adapt a function in the resource view. I want that when I access a record, I can set $record->is_read = 1; $record->save();, but I'm not sure where to place it. Is there an option for this? Thank you very much.
8 Replies
Maybe in the mount() method?
i have ViewContact, i try with __construct, run dd() and its ok, but i should show the $record
Mount is where you should do this. Livewire components can’t be instantiated and there fire aren’t invokable, per say.
I would definitely put a check in for it though so it isn’t trying to save it every time component is mounted.
In the ViewRecord page you should have access to $this->record.
$this->record.
You also need to call parent::mount() first.
RUNNIIIINGG , Thanks you
You should still check if is_read is equal to true though, before setting it and calling save. There’s no reason to waste db calls to update something that is already set.