PHP code example of amuzcorp / laravel-custom-session-handler
1. Go to this page and download the library: Download amuzcorp/laravel-custom-session-handler 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/ */
amuzcorp / laravel-custom-session-handler example snippets
Session::extend('custom_database', function ($app) {
$handler = new CustomDatabaseSessionHandler(
DB::connection(config('session.connection')),
config('session.table'),
config('session.lifetime'),
$app
);
// route 이름 기반으로 제외
$handler->excludeRoutes([
'health.check',
'api.metrics',
]);
// callback 기반으로 제외
$handler->addExclusionCallback(function ($request) {
return str_contains($request->userAgent(), 'HealthChecker');
});
return $handler;
});
use Illuminate\Support\Facades\Route;
Route::get('/health', function () {
return response()->json(['status' => 'ok']);
})->name('health.check');
Route::get('/dashboard', function () {
session(['visited' => now()]); // 세션이 업데이트되어야 함
return view('dashboard');
});
bash
php artisan vendor:publish --provider="Amuz\CustomSession\CustomSessionServiceProvider" --tag=config