Installation
composer require cvepdb-cms/module-dashboard
Add the service provider to config/app.php under providers:
Cvepdb\Dashboard\DashboardServiceProvider::class,
Publish Configuration
php artisan vendor:publish --provider="Cvepdb\Dashboard\DashboardServiceProvider" --tag="config"
This generates config/dashboard.php. Review and customize:
First Use Case: Displaying the Dashboard Add the dashboard blade directive to your layout:
@dashboard
Or manually render a widget:
use Cvepdb\Dashboard\Widgets\RecentCvesWidget;
$widget = new RecentCvesWidget();
echo $widget->render();
Key Configuration
dashboard.default_widgets to control which widgets load by default.dashboard.cache to enable/disable widget caching (recommended for production).Creating Custom Widgets
Extend Cvepdb\Dashboard\AbstractWidget:
namespace App\Dashboard\Widgets;
use Cvepdb\Dashboard\AbstractWidget;
class CustomCveStatsWidget extends AbstractWidget
{
public function render()
{
return view('dashboard.widgets.custom-cve-stats', [
'stats' => $this->getStats(),
]);
}
protected function getStats()
{
return Cve::stats();
}
}
Registering Widgets Bind your widget to the container in a service provider:
$this->app->bind('dashboard.widgets.custom-cve-stats', function ($app) {
return new \App\Dashboard\Widgets\CustomCveStatsWidget();
});
Dynamic Widget Loading
Use the Dashboard facade to load widgets dynamically:
use Cvepdb\Dashboard\Facades\Dashboard;
$widgets = Dashboard::load(['recent-cves', 'custom-cve-stats']);
Dashboard Sections
Use @dashboard.section to create named sections:
@dashboard.section('security-metrics')
@foreach($widgets as $widget)
{!! $widget->render() !!}
@endforeach
@enddashboard
Conditional Widgets
Leverage visibility rules in config/dashboard.php:
'visibility' => [
'recent-cves' => function () {
return auth()->user()->can('view_cves');
},
],
Eager Loading Data Preload widget data in a controller:
public function dashboard()
{
$widgets = Dashboard::load(['recent-cves', 'vulnerability-trends']);
$widgets->each->loadData(); // Calls $widget->loadData() if defined
return view('dashboard', compact('widgets'));
}
Caching Strategies Cache widget data for 5 minutes:
public function loadData()
{
return Cache::remember("dashboard_{$this->getCacheKey()}", now()->addMinutes(5), function () {
return $this->fetchFreshData();
});
}
Widget Registration Order
app.custom-cve-stats).Cache Invalidation
Cvepdb\Dashboard\Contracts\CacheableWidget and call:
Dashboard::invalidateCache('widget-name');
Blade Directives Conflicts
@dashboard may conflict with other packages using @ directives.echo Dashboard::render();
Widget Debug Mode
Enable in config/dashboard.php:
'debug' => env('APP_DEBUG', false),
Widget Isolation
config/dashboard.php:
'default_widgets' => ['recent-cves'], // Only load this widget
Performance Profiling
use Barryvdh\Debugbar\Facades\Debugbar;
public function loadData()
{
Debugbar::info('Widget Data Load', ['source' => 'database']);
return Model::query()->get();
}
Custom Widget Events
Dashboard::listen('widget.rendered', function ($widget) {
// Log or process widget output
});
Widget Middleware
middleware method:
class CustomWidget extends AbstractWidget
{
public function middleware()
{
return [\App\Http\Middleware\CheckPermission::class];
}
}
Internationalization
public function getLabel()
{
return trans('dashboard.widgets.recent_cves.label');
}
php artisan vendor:publish --tag=dashboard-lang
How can I help you explore Laravel packages today?