DB::transaction(function() {
// Do something
dispatch(function() use ($model) {
$model->notify();
})->onConnection('transaction-commit');
});
class ProcessExample {
public function run() {
DB::transaction(function() {
// Do something more
$this->nestedRun();
});
}
public function nestedRun() {
DB::transaction(function() {
$model = new NotifiableExampleModel();
// This job will be fired when all the transactions have been commited.
dispatch(function() use ($model) {
$model->notify();
})->onConnection('transaction-commit');
});
}
}
$command = new ProcessExample();
$command->run();
DB::connection('other-connection')->transaction(function() {
// Do something
$model = new NotifiableExampleModel();
dispatch(function() use ($model) {
$model->notify();
})->onConnection('transaction-commit')->onQueue('other-connection');
});