Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
114 lines
3.1 KiB
PHP
114 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Applications;
|
|
|
|
use App\Filament\Resources\Applications\Pages\ListApplications;
|
|
use App\Filament\Resources\Applications\Pages\ViewApplication;
|
|
use App\Filament\Resources\Applications\Schemas\ApplicationInfolist;
|
|
use App\Filament\Resources\Applications\Tables\ApplicationsTable;
|
|
use App\Models\Application;
|
|
use BackedEnum;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use UnitEnum;
|
|
|
|
/**
|
|
* The inbox.
|
|
*
|
|
* Everything else in this panel is written by the collective; this is the one
|
|
* resource written by the public. That difference shapes the whole thing:
|
|
* nothing here is created by hand, the submitted half is read-only, and the
|
|
* badge in the sidebar counts the people still waiting for a reply.
|
|
*/
|
|
class ApplicationResource extends Resource
|
|
{
|
|
protected static ?string $model = Application::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedInboxArrowDown;
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
public static function getModelLabel(): string
|
|
{
|
|
return __('panel.applications.label');
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return __('panel.applications.plural');
|
|
}
|
|
|
|
public static function getNavigationGroup(): string|UnitEnum|null
|
|
{
|
|
return __('panel.groups.collective');
|
|
}
|
|
|
|
public static function getRecordTitle(?Model $record): ?string
|
|
{
|
|
return $record?->name;
|
|
}
|
|
|
|
public static function infolist(Schema $schema): Schema
|
|
{
|
|
return ApplicationInfolist::configure($schema);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return ApplicationsTable::configure($table);
|
|
}
|
|
|
|
/**
|
|
* @return Builder<Application>
|
|
*/
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
// `subject()` reads the call on every row, and the handler shows in an
|
|
// optional column: both are loaded up front rather than per row.
|
|
return parent::getEloquentQuery()->with(['call', 'handler']);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListApplications::route('/'),
|
|
'view' => ViewApplication::route('/{record}'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Submissions arrive from the public site. Nobody types one in.
|
|
*/
|
|
public static function canCreate(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* The number of people waiting for an answer — the only figure in this
|
|
* panel that represents somebody else's time rather than ours.
|
|
*/
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
$pending = static::getModel()::query()->pending()->count();
|
|
|
|
return $pending > 0 ? (string) $pending : null;
|
|
}
|
|
|
|
public static function getNavigationBadgeColor(): ?string
|
|
{
|
|
return 'warning';
|
|
}
|
|
|
|
public static function getNavigationBadgeTooltip(): ?string
|
|
{
|
|
return __('panel.applications.badge_tooltip');
|
|
}
|
|
}
|