Created
January 15, 2017 14:40
-
-
Save aambrozkiewicz/5b38416fc84a824649b1a137bd4fa84c to your computer and use it in GitHub Desktop.
Laravel Middleware with Database transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class Transactional | |
{ | |
public function handle($request, Closure $next) | |
{ | |
\DB::beginTransaction(); | |
$response = $next($request); | |
if ($response->exception) { | |
\DB::rollBack(); | |
} else { | |
\DB::commit(); | |
} | |
return $response; | |
} | |
} |
Sure, I've used it few projects before
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Out of interested - did you test it ?