laravel事务
程序员文章站
2024-01-02 20:08:58
...
DB::transaction(function () {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
如何传递参数到匿名函数内呢,如果我这样写,报错
DB::transaction(function ($a, $b, $c) {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
回复内容:
DB::transaction(function () {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
如何传递参数到匿名函数内呢,如果我这样写,报错
DB::transaction(function ($a, $b, $c) {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
DB::transaction(function() use ($a, $b, $c) {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});