ホームページ  >  記事  >  バックエンド開発  >  laravel事务

laravel事务

WBOY
WBOYオリジナル
2016-06-06 20:15:11946ブラウズ

<code>DB::transaction(function () {
    DB::table('users')->update(['votes' => 1]);
    DB::table('posts')->delete();
});
</code>

如何传递参数到匿名函数内呢,如果我这样写,报错

<code>DB::transaction(function ($a, $b, $c) {
    DB::table('users')->update(['votes' => 1]);
    DB::table('posts')->delete();
});</code>

回复内容:

<code>DB::transaction(function () {
    DB::table('users')->update(['votes' => 1]);
    DB::table('posts')->delete();
});
</code>

如何传递参数到匿名函数内呢,如果我这样写,报错

<code>DB::transaction(function ($a, $b, $c) {
    DB::table('users')->update(['votes' => 1]);
    DB::table('posts')->delete();
});</code>

<code>DB::transaction(function() use ($a, $b, $c) {
    DB::table('users')->update(['votes' => 1]);
    DB::table('posts')->delete();
});</code>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。