PHP code example of gheith3 / filament-relation-pages

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

    

gheith3 / filament-relation-pages example snippets


use gheith3\FilamentRelationPages\RelationPage;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Contracts\View\View;

class BuildingSummaryPage extends RelationPage
{
    protected static ?string $title = 'Summary';
    protected static string|BackedEnum|null $icon = 'heroicon-o-chart-bar';

    public function content(Schema $schema): Schema
    {
        return $schema->components([
            Section::make('Overview')->columns(3)->schema([
                TextEntry::make('name')->state($this->ownerRecord->name),
                TextEntry::make('units')->state($this->ownerRecord->units()->count()),
            ]),
        ]);
    }

    public function render(): View
    {
        return view('filament.resources.buildings.building-summary-page');
    }
}

// app/Filament/Resources/BuildingResource.php

public static function getRelations(): array
{
    return [
        RelationPages\BuildingSummaryPage::class,   // ← custom tab
        RelationManagers\UnitsRelationManager::class,
        // ...
    ];
}

protected static ?string $title      = 'My Tab';
protected static ?string $icon       = 'heroicon-o-chart-bar';
protected static ?string $badge      = null;   // static badge text
protected static ?string $badgeColor = 'info';

public static function getBadge(Model $ownerRecord, string $pageClass): ?string
{
    return (string) $ownerRecord->items()->count();
}

public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
    return $ownerRecord->is_active;
}

protected static bool $isLazy = true;

public function stats(Schema $schema): Schema { ... }
public function details(Schema $schema): Schema { ... }

public static function getDefaultProperties(): array
{
    return ['mode' => 'compact'];
}

// Then in the class:
public string $mode = 'compact';
bash
php artisan make:filament-relation-page BuildingSummaryPage --resource=Buildings

app/Filament/Resources/Buildings/RelationPages/BuildingSummaryPage.php
resources/views/filament/resources/buildings/building-summary-page.blade.php
blade
{{ $this->stats }}
{{ $this->details }}
bash
php artisan vendor:publish --tag=filament-relation-pages-stubs