I came here looking how to wrap a self-made database seeder in a transaction.
The function for that is DB::transaction(function(){});
With that said, DB is a facade. According to the Laravel Facade Documentation DB references both DatabaseManager and Connection.
If you are using standalone Eloquent, you'll want to get the connection out of the Capsule object. Code ends up looking something like this:
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
$db = $capsule->getConnection();
$db->transaction(function()
{
// your transaction code here
});