Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Last active November 16, 2018 21:40
Show Gist options
  • Save wilcorrea/dfc082babedfd39246f9e913a235c8b9 to your computer and use it in GitHub Desktop.
Save wilcorrea/dfc082babedfd39246f9e913a235c8b9 to your computer and use it in GitHub Desktop.
<?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