0

I am working with Laravel Transactions. I came across a weird thing can anyone help me out to explain the same.

I start DB::transaction() in my base controller construct like the following

Controller.php

public function __construct(){
    DB::transaction();
}

This will be used in any other controller functions as follows

class ProductsController extends Controller{
    function testing(){
        try{
            //Code which works
            if(//notworks){
                throw new Exception('Yo! Something fucked up');
            }

            DB::commit();
        }catch(Exception $e){
            DB::rollback();
        }
    }
}

For the first time, I omitted the DB::commit and then the very next time I added it. Instead of having id as 1 it added 2. Again I retested the same with same steps so instead of 3 it added 4

As per my knowledge that row is locked or something.

What exactly is happening? Any help on the same will be really appreciated.

Channaveer Hakari
  • 2,769
  • 3
  • 34
  • 45

0 Answers0