Skip to content

Instantly share code, notes, and snippets.

@sanathks
Created September 4, 2018 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanathks/2a3173f798095bb600843e56400c5b91 to your computer and use it in GitHub Desktop.
Save sanathks/2a3173f798095bb600843e56400c5b91 to your computer and use it in GitHub Desktop.
Laravel Database transaction middleware
<?php
namespace Core\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Validation\UnauthorizedException;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;
class DatabaseTransactions
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
public function handle($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