imransaleem / http-db-logger
Middleware to log HTTP requests and responses to database
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/imransaleem/http-db-logger
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
This package is not auto-updated.
Last update: 2025-12-31 07:49:41 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:
idmethoduriipheadersbodycreated_by(nullable)user_role(nullable)created_at/updated_at
© 2025 Imran Saleem — Licensed under MIT