PHP code example of johnrivera7 / filament-custom-dashboard-widgets

1. Go to this page and download the library: Download johnrivera7/filament-custom-dashboard-widgets 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/ */

    

johnrivera7 / filament-custom-dashboard-widgets example snippets


use JohnRivera7\FilamentWidgetGrid\FilamentWidgetGridPlugin;

$panel->plugins([
    FilamentWidgetGridPlugin::make()
        ->canViewWidget(fn (string $widget): bool => auth()->user()?->can('view', $widget) ?? false)
        ->canCustomize(fn (): bool => auth()->check())
        ->canManageDefaults(fn (): bool => auth()->user()?->hasRole('super_admin') ?? false),
]);

use Filament\Pages\Dashboard as BaseDashboard;
use JohnRivera7\FilamentWidgetGrid\Concerns\HasWidgetGrid;

class Dashboard extends BaseDashboard
{
    use HasWidgetGrid;

    public function getWidgets(): array
    {
        return [
            \App\Filament\Widgets\StatsOverview::class,
            \App\Filament\Widgets\OrdersChart::class,
        ];
    }
}

FilamentWidgetGridPlugin::make()
    ->columns(24)
    ->cellHeight(45)
    ->maxHeight(60)
    ->density('comfortable') // or 'compact'
    ->float(true)
    ->templates(true)
    ->canViewWidget(...)
    ->canCustomize(...)
    ->canManageDefaults(...)
    ->canShareTemplates(...);

public static int $gridW = 12;
public static int $gridH = 10;
public static int $gridMinH = 4;
public static bool $gridSizeToContent = true;