php - laravel execute code after return
776
Solution:
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.
Answer
Solution:
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_viewed
value that it gets by reaching directly into$conversation
. Don't do that. Save the previouslast_viewed
value before you update the database into a variable, pass that variable into the view and have the view compare with that.