No Index, only EditRecord with RelationManager

Hi all, Each user of my application has a "HasOne" relationship to a model called Volunteer. I'd like to make a page a bit like MyProfile BUT, I need to have a RelationManager on this page and I can't see how to do it other than on a resource one. So how can I create a resource that has no index and only an Edit page that points to auth()->user() ? Thank you for your advice
2 Replies
leoblanski
leoblanski5mo ago
Hey @Gustave I've done something similar but using Resource. Created a resource that has just a single edit page, without View and Index... Take a look if it helps you. Resource:
public static function getPages(): array
{
return [
'edit' => Pages\EditTeam::route('/{record}/edit'),
'index' => Pages\EditTeam::route("/settings/edit"),
];
}
public static function getPages(): array
{
return [
'edit' => Pages\EditTeam::route('/{record}/edit'),
'index' => Pages\EditTeam::route("/settings/edit"),
];
}
Inside EditTeam i have:
class EditTeam extends EditRecord
{
protected static string $resource = TeamResource::class;

public function mount(int | string $record): void
{
$this->record = auth()->user()->team;

static::authorizeResourceAccess();
$this->fillForm();
}

protected function afterSave()
{
redirect()->route('filament.user.resources.team.edit', ['record' => $this->record->id]);
}
}
class EditTeam extends EditRecord
{
protected static string $resource = TeamResource::class;

public function mount(int | string $record): void
{
$this->record = auth()->user()->team;

static::authorizeResourceAccess();
$this->fillForm();
}

protected function afterSave()
{
redirect()->route('filament.user.resources.team.edit', ['record' => $this->record->id]);
}
}
Gustave
Gustave5mo ago
Thank you !