php - laravel execute code after return
Using Laravel, you can run such tasks after sending the response to the user. It works by keeping the PHP process alive to run the tasks after closing the connection with the browser. You can do that using:
Job::dispatchAfterResponse() using Laravel v6.14.0 or higher.
You are thinking about the problem the wrong way. You don't need to update the data after the view has been displayed; instead of this, simply let the view know about what is going on.
Presumably right now the view knows if a message is unread or not by comparing some timestamp with a
last_viewedvalue that it gets by reaching directly into
$conversation. Don't do that. Save the previous
last_viewedvalue before you update the database into a variable, pass that variable into the view and have the view compare with that.