Skip to content

Instantly share code, notes, and snippets.

@sawirricardo
Last active November 22, 2023 13:33
Show Gist options
  • Save sawirricardo/ff547ba3afebe0139aeb49404fe88c51 to your computer and use it in GitHub Desktop.
Save sawirricardo/ff547ba3afebe0139aeb49404fe88c51 to your computer and use it in GitHub Desktop.
It captures responses, handles DB transactions, and allows custom error messages.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class TransactionEncapsulation
{
public function handle(Request $request, Closure $next)
{
return DB::transaction(function () use ($request, $next) {
return $next($request);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment