国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

[已解決]webman使用事務(wù)無效,回滾了,數(shù)據(jù)依然添加成功

shyrank

bug描述

webman使用事務(wù)無效,回滾了,數(shù)據(jù)依然添加成功,使用的是 illuminate/database

程序代碼或配置

<?php
declare(strict_types=1);

namespace App\api\controller\Base;
use App\common\model\collections\Collections;
use App\common\model\collections\CollectionsWarehouse;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator;
use support\Db;
use support\package\Auth\UserAuth;
use support\Request;
use support\Response;
use App\api\controller\Controller;
use think\Validate;

class Ping extends Controller
{

    public function getRules(): array
    {
        return [
            'index'=>[
                'rules'=>[
                    'name' => 'require|integer|>=:0',
                ],
                'message'=>[
                    'name.require' => '名字是必須傳的,狗日的',
                ]
            ]
        ];
    }

    public function index(Request $request): Response
    {
        Db::beginTransaction();
        CollectionsWarehouse::query()->create([
            'user_id'=>'111',
            'serial_number'=>1,
            'collection_id'=>1,
            'gift_number'=>1,
            'term_date'=>time(),
            'update_time'=>time(),
        ]);
        Db::rollBack();
        return json(['11111']);
    }

}
2341 1 1
1個回答

shyrank

找到問題了,是model里面的這個參數(shù)問題 $fillable,會導(dǎo)致事務(wù)失效

  • sharf 2023-11-08

    Db::connection('mysql')->beginTransaction();

  • sharf 2023-11-08

    model里定義了連接 protected $connection = 'mysql';,需要 Db::connection('mysql')->beginTransaction();

年代過于久遠(yuǎn),無法發(fā)表回答
??