czogori/rentgen
Laravel package for generating and validating Rentgen-style identifiers and numbers, with helpers for formatting, checksum calculation, and simple integration into apps. Useful for input validation, data imports, and consistent ID handling.
Installation
composer require czogori/rentgen
Add the service provider to config/app.php:
'providers' => [
// ...
Czogori\Rentgen\RentgenServiceProvider::class,
],
Basic Usage Rentgen is a data visualization and reporting tool for Laravel. Start by publishing its config:
php artisan vendor:publish --provider="Czogori\Rentgen\RentgenServiceProvider"
This generates a config file at config/rentgen.php.
First Use Case: Query Visualization Use Rentgen to log and visualize database queries in real-time:
use Czogori\Rentgen\Facades\Rentgen;
// Enable query logging
Rentgen::enableQueryLogging();
// Run a query (e.g., in a controller or service)
$users = User::where('active', true)->get();
// View queries in `/rentgen` (if configured)
Query Logging & Debugging
Rentgen::enableQueryLogging(); // Global
Rentgen::enableQueryLogging(true, ['User']); // Per-model
/rentgen (or custom route) to see:
Reporting & Analytics
Rentgen::logEvent('checkout_completed', [
'user_id' => auth()->id(),
'amount' => $order->total,
]);
Rentgen::export() method to generate CSV/JSON reports:
$data = Rentgen::export('queries', 'last_7_days');
Integration with Laravel Features
public function handle($request, Closure $next) {
Rentgen::enableQueryLogging();
return $next($request);
}
Rentgen\Events\QueryLogged to process queries in real-time:
event(new Rentgen\Events\QueryLogged($query));
Performance Profiling
Rentgen::tagQuery('admin_dashboard');
Memory Usage
Rentgen::flush() to clear logs periodically.config/rentgen.php:
'storage' => 'database', // Store logs in DB instead of memory
Route Conflicts
/rentgen route may conflict with other packages. Override it in config:
'dashboard_route' => 'admin/performance',
Query Overhead
if (app()->environment('production')) {
Rentgen::disableQueryLogging();
}
Database Storage Quirks
database storage, ensure the rentgen_logs table exists. Run:
php artisan rentgen:install
Rentgen::pruneLogs(Carbon::now()->subDays(30));
Custom Query Formatting Extend the query formatter to highlight slow queries:
Rentgen::extend('formatter', function ($query) {
if ($query->duration > 100) { // ms
return "<span style='color:red'>$query->sql</span>";
}
return $query->sql;
});
API Access Expose Rentgen data via an API endpoint:
Route::get('/api/performance', function () {
return Rentgen::getLogs()->take(100);
});
Slack/Email Alerts
Trigger alerts for slow queries using Laravel's Handle facade:
use Czogori\Rentgen\Events\QueryLogged;
QueryLogged::listen(function ($query) {
if ($query->duration > 500) { // 500ms threshold
Notification::route('slack', 'channel-id')
->notify(new SlowQueryAlert($query));
}
});
Testing Mock Rentgen in tests to avoid logging:
$this->partialMock(Rentgen::class, ['logQuery'])
->shouldReceive('logQuery')
->andReturnNull();
Configuration Overrides Dynamically adjust settings per request:
Rentgen::setConfig([
'log_bindings' => true, // Enable for current request only
]);
How can I help you explore Laravel packages today?