PHP code example of shiftonelabs / laravel-db-events

1. Go to this page and download the library: Download shiftonelabs/laravel-db-events library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shiftonelabs / laravel-db-events example snippets


'ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider',

ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider::class,

$app->register(ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider::class);

app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    app('log')->info('Connector class: '.get_class($event->connector));
    app('log')->info('Connection name: '.$event->connectionName);
    app('log')->info('Configuration: '.print_r($event->config, true));
});

app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    // don't connect to mysql in strict mode if you like zeroed out dates
    if (i_like_zero_dates()) {
        $event->config['strict'] = false;
    }
});

app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    if (not_todaaay()) {
        return false;
    }
});

app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnected', function ($event) {
    app('log')->info('Connector class: '.get_class($event->connector));
    app('log')->info('Connection name: '.$event->connectionName);
    app('log')->info('Configuration: '.print_r($event->config, true));
    app('log')->info('PDO class: '.get_class($event->pdo));
});