Take a look at Eloquent observers. https://laravel.com/docs/9.x/eloquent#defining-observers You can set this up to listen for the relevant events that are (by default) fired on any Eloquent model during a given transaction and place your boolean-modification code there, and define it for each eloquent model that needs this treatment.
May 25, 2022
3
Level 12
Run DB query on each insert into a specific table
Hey!
I need to somehow change a boolean value of a column inside a table (websites) based on every insert in another table (reviews). Both tables have relationship. On a new review inserted into the reviews table I need to change a boolean value in websites table (webscore_recalculation_needed to true) to which the review refers (reviews.website_id). Do you guys have any idea how to do that? Note that I'm not using only 1 method, I'm using Eloquent & DB Query Builder (BOTH) in the whole application.
Level 12
I did this with event & listener.
Please or to participate in this conversation.