小编Mat*_*Boy的帖子

Laravel 数据库事务不起作用

我正在尝试在Laravel 5.5 中设置数据库事务但它似乎不起作用。我使用MySQL 5.7.20,工具模式中的所有表都是 InnoDB。我也在运行PHP 7.2.3

我有这个代码:

DB::beginTransaction();
try {
    // checks whether the users marked for removal are already assigned to the list
    foreach ($removeStudents as $removeStudent) {
        if ($ls->allocatedStudents->find($removeStudent->id) === null) {
            throw new Exception('userNotAllocated', $removeStudent->id);
        } else {
            DB::connection('tools')->table('exercises_list_allocations')
                ->where('user_id', $removeStudent->id)
                ->where('exercises_list_id', $ls->id)
                ->delete();
        }
    }

    // checks whether the users marked for removal are already assigned to the list
    foreach ($addStudents as $addStudent) {
        if ($ls->allocatedStudents->find($addStudent->id) …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel

7
推荐指数
1
解决办法
3042
查看次数

标签 统计

laravel ×1

mysql ×1

php ×1