imransaleem / http-db-logger
Middleware to log HTTP requests and responses to database
v1.0.1
2025-09-24 04:36 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
This package is not auto-updated.
Last update: 2025-09-24 06:42:38 UTC
README
A Laravel middleware package to log all incoming HTTP requests into the database.
📦 Installation
You can install the package via Composer:
composer require imransaleem/http-db-logger
🔧 Configuration (Optional)
If you're not using Laravel package auto-discovery, add the service provider manually in config/app.php
:
'providers' => [ // Other service providers... Imransaleem\HttpDbLogger\HttpDbLoggerServiceProvider::class, ],
🛡 Register Middleware
Add the middleware in app/Http/Kernel.php
:
protected $middleware = [ // Other middleware... \Imransaleem\HttpDbLogger\Middleware\LogHttpToDatabase::class, ];
🚀 Publish Configuration & Migration
To publish the config and migration files, run:
php artisan vendor:publish --tag=config php artisan vendor:publish --tag=migrations
Then run the migration:
php artisan migrate
✅ Example Usage
You can apply the middleware to a specific route group like this:
use \Imransaleem\HttpDbLogger\Middleware\LogHttpToDatabase; Route::middleware(['auth', LogHttpToDatabase::class])->group(function () { Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); });
⚙️ Configuration Options
You can customize the logger via config/http-db-logger.php
. Options include:
log_requests
: boolean default true,log_authenticated_user
: Log user ID and role if authenticated.table
: logging table for database
🗃 Database Table
The package creates a http_db_logs
table with the following fields:
id
method
uri
ip
headers
body
created_by
(nullable)user_role
(nullable)created_at
/updated_at
© 2025 Imran Saleem — Licensed under MIT