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 B.V.
Proculair B.V.13mo ago
Maybe in the mount() method?
lucianosnchz
lucianosnchzOP13mo ago
i have ViewContact, i try with __construct, run dd() and its ok, but i should show the $record
awcodes
awcodes13mo 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
lucianosnchzOP13mo ago
No description
awcodes
awcodes13mo ago
$this->record. You also need to call parent::mount() first.
lucianosnchz
lucianosnchzOP13mo ago
RUNNIIIINGG , Thanks you
lucianosnchz
lucianosnchzOP13mo ago
No description
awcodes
awcodes13mo 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.
Want results from more Discord servers?
Add your server