laravel database的事务函数
时间:2021-07-01 10:21:17
帮助过:3人阅读
()
use (
$user_id,
$video_id,
$action_id) {
$this->create(
array(‘user_id‘ =>
$user_id, ‘video_id‘ =>
$video_id, ‘action_id‘ =>
$action_id));
if (UserTotalActionRecord::where(‘user_id‘,
$user_id)->where(‘action_id‘,
$action_id)->where(‘record_date‘,
date("Y-m-d"))->
first()) {
UserTotalActionRecord::where(‘user_id‘,
$user_id)->where(‘action_id‘,
$action_id)->where(‘record_date‘,
date("Y-m-d"))->increment(‘action_times‘
);
} else {
UserTotalActionRecord::create(
array(‘user_id‘ =>
$user_id, ‘action_id‘ =>
$action_id, ‘record_date‘ =>
date("Y-m-d"
)));
}
});
之前使用时发现匿名函数没用 use 来引用外部变量,使得在函数体内使用时会出错,因此需注重匿名函数的使用。
laravel database的事务函数
标签: