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
Proculair
Proculair9mo ago
Maybe in the mount() method?
lucianosnchz
lucianosnchz9mo ago
i have ViewContact, i try with __construct, run dd() and its ok, but i should show the $record
awcodes
awcodes9mo ago
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.
lucianosnchz
lucianosnchz9mo ago
No description
awcodes
awcodes9mo ago
$this->record. You also need to call parent::mount() first.
lucianosnchz
lucianosnchz9mo ago
RUNNIIIINGG , Thanks you
lucianosnchz
lucianosnchz9mo ago
No description
awcodes
awcodes9mo ago
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.