PHP code example of anselmocossa / filament-launchpad

1. Go to this page and download the library: Download anselmocossa/filament-launchpad 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/ */

    

anselmocossa / filament-launchpad example snippets


use Filament\Launchpad\LaunchpadPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(LaunchpadPlugin::make());
}

namespace App\Filament\Launchpad;

use App\Models\Order;
use Filament\Launchpad\Launchpad\BaseKpiSource;
use Filament\Launchpad\Launchpad\KpiResult;

class SalesTodayKpi extends BaseKpiSource
{
    public function cacheFor(): ?int
    {
        return 120; // seconds; null = no TTL cache (still memoized once per request)
    }

    public function resolve(): KpiResult
    {
        return KpiResult::make(Order::whereDate('created_at', today())->count())
            ->unit('orders')
            ->trend('+3 today', 'success') // success | danger | gray
            ->badge('new');                // pass null to hide the badge
    }
}

use Filament\Launchpad\LaunchpadPlugin;

LaunchpadPlugin::make()
    ->kpis([\App\Filament\Launchpad\SalesTodayKpi::class])          // explicit
    ->discoverKpis(in: app_path('Metrics'), for: 'App\\Metrics')    // custom folder
    ->autoDiscoverKpis(false);                                      // opt out entirely

LaunchpadPlugin::make()->kpiSources([
    'open_tickets' => fn () => Ticket::whereNull('resolved_at')->count(),
]);

public function panels(): array
{
    return ['store'];
}

public function cacheKey(): string
{
    return static::key().':'.tenancy()->tenant()?->id;
}

namespace App\Filament\Launchpad;

use Filament\Launchpad\Launchpad\BaseCardPreset;

class SalesTodayCard extends BaseCardPreset
{
    protected string $title = 'Sales Today';

    protected ?string $subtitle = 'Point of Sale';

    protected ?string $icon = 'heroicon-o-banknotes';

    protected string $type = 'kpi';                  // kpi | shortcut | widget

    protected string $targetType = 'url';            // none | url | resource | page

    protected ?string $targetValue = '/admin/sales';

    // protected ?string $kpiSource = 'sales_today'; // optionally pre-wire a live KPI source
}

LaunchpadPlugin::make()->cardLibrary([
    ['key' => 'sales-today', 'title' => 'Sales Today', 'type' => 'kpi', 'target_type' => 'url', 'target_value' => '/admin/sales'],
]);

use App\Filament\Widgets\RevenueChart;
use Filament\Launchpad\LaunchpadPlugin;

LaunchpadPlugin::make()->widgets([
    [
        'key' => 'revenue-chart',
        'class' => RevenueChart::class,
        'label' => 'Revenue',
        'icon' => 'heroicon-o-chart-bar',
        'columnSpan' => 'full',
    ],
]);

return [
    'branding' => [
        'name' => 'Launchpad',
        'logo' => null,
    ],
    'accent_color' => '#16a34a',
    'dark_header' => false,
    'tile_sizing' => 'fluid', // 'fixed' (6 equal columns, 1/6 row width each) or 'fluid' (auto-fit, minmax 176px)
];

use Filament\Launchpad\LaunchpadPlugin;
use Illuminate\Database\Eloquent\Builder;

LaunchpadPlugin::make()
    ->visibilityRolesQuery(fn (Builder $query) => $query
        ->where('tenant_id', tenancy()->tenant()?->id));

use Filament\Launchpad\LaunchpadPlugin;

LaunchpadPlugin::make()
    ->visibilityRolesRequired();

LaunchpadPlugin::make()
    ->visibilityRolesRequired(fn (): bool => tenancy()->tenant() !== null);

use Filament\Launchpad\LaunchpadPlugin;

LaunchpadPlugin::make()
    ->resourceAccess(fn (string $resource): bool => $tenant->hasModule('core'));
bash
php artisan migrate
bash
php artisan vendor:publish --tag="launchpad-config"
php artisan vendor:publish --tag="launchpad-views"
php artisan vendor:publish --tag="launchpad-lang"
bash
php artisan make:launchpad-kpi SalesToday
# → app/Filament/Launchpad/SalesTodayKpi.php   ("Kpi" suffix added automatically)

php artisan make:launchpad-kpi SalesToday --model=Order
# → app/Filament/Launchpad/Order/SalesTodayKpi.php
bash
php artisan make:launchpad-card SalesToday
# → app/Filament/Launchpad/SalesTodayCard.php   ("Card" suffix added automatically)
bash
php artisan make:launchpad-widget Revenue            # → app/Filament/Launchpad/RevenueWidget.php
php artisan make:launchpad-widget Revenue --model=Order  # → app/Filament/Launchpad/Order/RevenueWidget.php
bash
php artisan vendor:publish --tag="launchpad-lang"