Created
February 27, 2022 12:39
-
-
Save cevin/a8a41cbb5263b59b44580f0df5971ab2 to your computer and use it in GitHub Desktop.
laravel transaction event test
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\Providers; | |
use Illuminate\Database\Events\ConnectionEvent; | |
use Illuminate\Database\Events\TransactionBeginning; | |
use Illuminate\Database\Events\TransactionCommitted; | |
use Illuminate\Database\Events\TransactionRolledBack; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Event::listen('eloquent.*', function ($event, $model) { | |
preg_match('/^eloquent.(\w+)\:\s+([\w+\\\]+)$/ix', $event, $match); | |
var_dump($match); | |
}); | |
Event::listen( | |
[TransactionBeginning::class, TransactionCommitted::class, TransactionRolledBack::class], | |
function (ConnectionEvent $event) { | |
var_dump(get_class($event)); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment