Stack:
Laravel v8, MySQL.
I working on a payroll system with Laravel.
I want the value of some columns to update if another column it depends on changes.
For example, if the Number of working days changes on the payrolls table, then the salary and other columns that depends on ‘Number of working days’ column should re-calculate based on the new value and save to the database.
How do I go about this?
Are there any Laravel packages that handles this efficiently?
2
Answers
I never tried it myself, but it seems like you could solve this with a MYSQL Trigger or event:
https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html
In
laravel
model, there areevents
you could use for example if the userfirst_name
orlast_name
is updated I want to update thefull_name
too like thisHere is all the
events
you could listen for:retrieved
,creating
,created
,updating
,updated
,saving
,saved
,deleting
,deleted
,trashed
,forceDeleted
,restoring
,restored
, andreplicating