If you have a DB transaction and want to return its result, there are at least two ways, see the example
1// 1. You can pass the parameter by reference 2$invoice = NULL; 3DB::transaction(function () use (&$invoice) { 4 $invoice = Invoice::create(...); 5 $invoice->items()->attach(...); 6}) 7 8// 2. Or shorter: just return trasaction result 9$invoice = DB::transaction(function () {10 $invoice = Invoice::create(...);11 $invoice->items()->attach(...);12 13 return $invoice;14});