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
public function panels(): array
{
return ['store'];
}
public function cacheKey(): string
{
return static::key().':'.tenancy()->tenant()?->id;
}
return KpiResult::make(Candidate::count())
->trend("+{$thisMonth} this month")
->sparkline($lastTwelveMonths); // area, in the launchpad accent color
return KpiResult::make($open)
->sparkline($applicationsPerWeek, 'bar', '#16a34a'); // bars, in a color of your choice
use Filament\Launchpad\LaunchpadPlugin;
if (class_exists(LaunchpadPlugin::class)) {
LaunchpadPlugin::provide(
kpis: [\Vendor\Package\Launchpad\PendingKpi::class],
cards: [
\Vendor\Package\Launchpad\PendingCard::class, // a CardPreset class
fn (): array => [/* preset arrays, built when the library is shown */],
],
);
}
LaunchpadPlugin::make()
->subNavigation(false) // hide the full-width bar below the topbar
->topbarNavigation(); // render spaces/pages beside the logo
LaunchpadPlugin::make()->bookmarks();
return [
'branding' => [
'name' => 'Launchpad',
'logo' => null,
],
'accent_color' => '#16a34a',
'dark_header' => false,
'tile_sizing' => 'fluid', // 'fixed' (up to 6 per row, never below the tile width) or 'fluid' (stretched to fill, in even rows: 9 tiles = 5 + 4)
'tile_icon_tone' => 'muted', // 'muted' (pale gray icons) or 'strong' (dark icons)
];
LaunchpadPlugin::make()
->tileIconTone('strong'); // 'muted' (default) or 'strong'
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();