Skip to content

Instantly share code, notes, and snippets.

@mohamad-supangat
Forked from aambrozkiewicz/Transactional.php
Created September 13, 2023 03:35
Show Gist options
  • Select an option

  • Save mohamad-supangat/5a0b297e1521abdb0ebcc52d491b4043 to your computer and use it in GitHub Desktop.

Select an option

Save mohamad-supangat/5a0b297e1521abdb0ebcc52d491b4043 to your computer and use it in GitHub Desktop.

Revisions

  1. Aleksander Ambrozkiewicz created this gist Jan 15, 2017.
    21 changes: 21 additions & 0 deletions Transactional.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?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;
    }
    }