Last active
November 16, 2018 21:40
-
-
Save wilcorrea/dfc082babedfd39246f9e913a235c8b9 to your computer and use it in GitHub Desktop.
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; | |
use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
use Illuminate\Support\Facades\DB; | |
/** | |
* Class Kernel | |
* @package App\Http | |
*/ | |
class Kernel extends HttpKernel | |
{ | |
/* ... */ | |
/** | |
* Bootstrap the application for HTTP requests. | |
* | |
* @return void | |
*/ | |
public function bootstrap() | |
{ | |
parent::bootstrap(); | |
DB::beginTransaction(); | |
} | |
/** | |
* Call the terminate method on any terminable middleware. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Illuminate\Http\Response $response | |
* @return void | |
*/ | |
public function terminate($request, $response) | |
{ | |
parent::terminate($request, $response); | |
if (!DB::transactionLevel()) { | |
return; | |
} | |
if ($response->isClientError() || $response->isServerError()) { | |
DB::rollBack(); | |
return; | |
} | |
DB::commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment