Laravel 7:在每个月的第一天自动将值添加到列
我想每个月在表中的所有行中为特定列增加值。
用户表:
ID | 离开_Alloc | feluf_earn |
---|---|---|
1 | 20 | 0 |
2 | 20 | 1.5 |
3 | 20 | -3 |
4 | 20 | 4 |
控制器:
public function earned_leave(){
$user = User::where('leave_alloc', '!=', null)->get();
foreach($user as $row){
$leave_alloc = $row->leave_alloc;
$earned_leave = $leave_alloc / 12;
$row->leave_earn += $earned_leave;
$row->save();
}
}
$ enned_leave
将是$ wept_alloc
由除以
的结果12
。因此,在每个月的第一天,我想将赢得的休假金额添加到所有用户的well_earn
列。此列可以具有负值和小数值。
我该如何进行自动化?
I want to add value to specific column for all rows in a table every month.
Users Table:
id | leave_alloc | leave_earn |
---|---|---|
1 | 20 | 0 |
2 | 20 | 1.5 |
3 | 20 | -3 |
4 | 20 | 4 |
Controller:
public function earned_leave(){
$user = User::where('leave_alloc', '!=', null)->get();
foreach($user as $row){
$leave_alloc = $row->leave_alloc;
$earned_leave = $leave_alloc / 12;
$row->leave_earn += $earned_leave;
$row->save();
}
}
Here $earned_leave
will be the result of $leave_alloc
divided by 12
. So, on the first day of every month, I want to add the earned leave amount to the leave_earn
column of all users. This column can hold a negative value and decimal value.
How can I make this automation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
laravel支持任务计划。对于您的任务,您可以使用
- > monthlyon(4,'15:00');
在最简单的实现中,看起来
别忘了添加
Laravel support task scheduling. For your task you may use
->monthlyOn(4, '15:00');
In most simple realization it looks like
Don't forget to add Cron entry