PHP code example of zdz / laravel-middleware-log

1. Go to this page and download the library: Download zdz/laravel-middleware-log 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/ */

    

zdz / laravel-middleware-log example snippets


// 在 App\Http\Kernel 类中...

protected $middleware = [
    \App\Http\Middleware\TrustProxies::class,
    \App\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
    \App\Http\Middleware\TrimStrings::class,
    \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    // 日志中间件
    \zdz\LaravelMiddlewareLog\WriteLogMiddleware::class,
];

// 在 App\Http\Kernel 类中...

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            // 日志中间件
            \zdz\LaravelMiddlewareLog\WriteLogMiddleware::class,
        ],
    ];

// 在 App\Http\Kernel 类中...
protected $routeMiddleware = [
    'auto_log' => \zdz\LaravelMiddlewareLog\WriteLogMiddleware::class,
];

Route::get('admin/profile', function () {
    //
})->middleware('auto_log');

// 在 App\Providers\EventServiceProvider 类中...
protected $listen = [
    Registered::class => [
        SendEmailVerificationNotification::class,
    ],
   // 添加sql监听 
    \Illuminate\Database\Events\QueryExecuted::class => [
        \zdz\LaravelMiddlewareLog\SqlLogListen::class
    ]
];
shell script
php artisan vendor:publish --provider="zdz\LaravelMiddlewareLog\LogServiceProvider"