Edit page as Index resource page

I have a resource that I want users to only edit. It doesn't make sense to show an index page with a list of resources. Therefore, I would like the "Tenant" menu, for example, to directly open the edit page with the form to make changes. I could not set the Pages with the ID because I have no information about session at this point. Normal resource:
public static function getPages(): array
{
return [
'index' => Pages\ListTeams::route('/'),
'create' => Pages\CreateTeam::route('/create'),
'edit' => Pages\EditTeam::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTeams::route('/'),
'create' => Pages\CreateTeam::route('/create'),
'edit' => Pages\EditTeam::route('/{record}/edit'),
];
}
I want to do something like:
public static function getPages(): array
{
return [
'index' => Pages\EditTeam::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\EditTeam::route('/{record}/edit'),
];
}
I've attempted to use custom pages that extend from Page and fill on mount function, but it returns errors. Missing required parameter for [Route: filament.user.resources.teams.index] [URI: teams/{record}/edit] [Missing parameter: record]. It's because when Panel is mounted, doesn't have information about which ID Tenant will edit.
1 Reply
leoblanski
leoblanskiOP12mo ago
I've already tried passing "wrong" id on route and fix on mount() function with session information, but returns error before mount execute. Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class App\Filament\User\Resources\TeamResource\Pages\EditTeam Found a solution.
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"),
];
}


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();
}
....
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();
}
....
Want results from more Discord servers?
Add your server