Files
landing-api/app/Filament/Resources/Calls/RelationManagers/ApplicationsRelationManager.php
Josep Piguillem 3897113313 Initial commit: Pireon Admin — headless admin panel and public API
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>
2026-08-19 17:55:27 +02:00

94 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Resources\Calls\RelationManagers;
use App\Enums\ApplicationStatus;
use App\Filament\Resources\Applications\ApplicationResource;
use App\Models\Application;
use Filament\Actions\Action;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
/**
* Who answered this call, shown on the call itself.
*
* The inbox is the place to work through everything at once; this is the place
* to answer the question you actually have while looking at an opening — is
* anybody interested? A call with no replies after a month is telling you
* something about the call, not about the people.
*/
class ApplicationsRelationManager extends RelationManager
{
protected static string $relationship = 'applications';
public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('panel.applications.plural');
}
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
{
$pending = $ownerRecord->applications()->pending()->count();
return $pending > 0 ? (string) $pending : null;
}
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
// The inbox holds personal data, so it stays behind its own permission
// even for someone already allowed to edit the call.
return (bool) Auth::user()?->can('applications.view_any');
}
public function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
TextColumn::make('name')
->label(__('panel.applications.fields.name'))
->weight('medium')
->description(fn (Application $record) => $record->email),
TextColumn::make('hours_per_week')
->label(__('panel.applications.fields.hours_per_week'))
->badge()
->color('info')
->formatStateUsing(fn (?int $state) => $state ? "{$state} h" : '—'),
TextColumn::make('status')
->label(__('panel.applications.fields.status'))
->badge(),
TextColumn::make('created_at')
->label(__('panel.applications.fields.received_at'))
->since()
->dateTimeTooltip(),
])
->recordActions([
Action::make('open')
->label(__('panel.applications.actions.open'))
->icon('heroicon-o-arrow-top-right-on-square')
->url(fn (Application $record) => ApplicationResource::getUrl('view', ['record' => $record])),
Action::make('mark_contacted')
->label(__('panel.applications.actions.contacted'))
->icon('heroicon-o-chat-bubble-left-right')
->color('info')
->authorize('update')
->visible(fn (Application $record) => $record->status === ApplicationStatus::New)
->action(fn (Application $record) => $record->markAs(
ApplicationStatus::Contacted,
Auth::user(),
)),
])
->emptyStateHeading(__('panel.applications.empty.call_heading'))
->emptyStateIcon('heroicon-o-inbox');
}
}