I'm using Lumen with a SQLite DB. I've tried everything I can think of to use DB::transaction
in Lumen, but to no avail. I consistently get errors like this:
ReflectionException: /vendor/illuminate/container/Container.php line 779
I've tried putting use DB;
at the top of the class. I've tried use
ing the facade. Nothing seems to work.
Simple example of trying to use it:
DB::transaction(function () use ($attributes, $service) {
$this->person = $this->person->create([]);
// do some other stuff
});
I've struggled to use transactions using
DB::transaction
in Lumen myself. A workaround that I ended up using is to just resolve the database using the global functionapp()
instead of the facade and then use the transaction on that like so:If there are a lot of these you can also cache the result of calling
app('db')
in a variable for reuse. It will behave just like the static calls onDB
.