PHP code example of manggala / laravel-dashboard-builder
1. Go to this page and download the library: Download manggala/laravel-dashboard-builder 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/ */
manggala / laravel-dashboard-builder example snippets
use Manggala\DashboardBuilder\Models\Dashboard;
use Illuminate\Support\Facades\Gate;
// Check authorization before rendering or editing
Gate::authorize('update', $dashboard);
use Manggala\DashboardBuilder\Facades\Dashboard;
use Manggala\DashboardBuilder\Widgets\Stats\CardWidget;
use Manggala\DashboardBuilder\Widgets\Charts\LineChartWidget;
use Manggala\DashboardBuilder\Widgets\Special\TableWidget;
use App\Models\User;
use App\Models\Order;
$salesDashboard = Dashboard::make('Sales & Revenue')
->description('Monthly sales metrics and performance breakdown')
->widget(
CardWidget::make('Total Users')
->model(User::class)
->count()
->icon('users')
->width(3)
->height(2)
)
->widget(
LineChartWidget::make('Revenue Trend')
->model(Order::class)
->sum('total_amount')
->groupByMonth()
->width(6)
->height(4)
)
->widget(
TableWidget::make('Recent Orders')
->table('orders')
->columns(['id', 'user_id', 'total_amount', 'status'])
->perPage(5)
->width(12)
);
// Convert to array or JSON payload
$payload = $salesDashboard->toArray();
bash
# Generate a new Dashboard class in app/Dashboards/
php artisan make:dashboard SalesDashboard
# Generate a new custom Widget class in app/Dashboards/Widgets/
php artisan make:dashboard-widget RevenueWidget
# Clear cached widget datasets
php artisan dashboard:clear-cache
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.