F
Filamentβ€’13mo ago
lazydog

Custom Page

I've added a custom page to my EventResource, specifically the
```
public static function getPages(): array
{
return [
'index' => Pages\ListEvents::route('/'),
'create' => Pages\CreateEvent::route('/create'),
'view' => Pages\ViewEvent::route('/{record}'),
'edit' => Pages\EditEvent::route('/{record}/edit'),
'take-attendance' => Pages\TakeAttendance::route('/{record}/take-attendance'),
];
}
```
public static function getPages(): array
{
return [
'index' => Pages\ListEvents::route('/'),
'create' => Pages\CreateEvent::route('/create'),
'view' => Pages\ViewEvent::route('/{record}'),
'edit' => Pages\EditEvent::route('/{record}/edit'),
'take-attendance' => Pages\TakeAttendance::route('/{record}/take-attendance'),
];
}
I implemented the HasInfolist
class TakeAttendance extends Page implements HasInfolists
{
use InteractsWithRecord;

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->record(Event::first())
->schema([]);
}
class TakeAttendance extends Page implements HasInfolists
{
use InteractsWithRecord;

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->record(Event::first())
->schema([]);
}
When I browse this userl admin/events/1/take-attendance , how can I get the Event data that has an ID of 1 and put it in my
->record(SpecificEvent Here)
->record(SpecificEvent Here)
So that I can use it in viewing data
Solution:
static methods are for resources to be retrieved by the "page" class later. If you declare directly in the page class, it should be public function infolist(Infolist $infolist): Infolist
Jump to solution
6 Replies
lazydog
lazydogOPβ€’13mo ago
I can't use
$this
$this
inside infolist method
IndomieRendang
IndomieRendangβ€’13mo ago
why static?
lazydog
lazydogOPβ€’13mo ago
I just copied it from my main resource. What should be?
Solution
IndomieRendang
IndomieRendangβ€’13mo ago
static methods are for resources to be retrieved by the "page" class later. If you declare directly in the page class, it should be public function infolist(Infolist $infolist): Infolist
lazydog
lazydogOPβ€’13mo ago
ohh nice! that's new to me. It works. thanks for the knowledge πŸ™‚
IndomieRendang
IndomieRendangβ€’13mo ago
yepp... that also applies for other methods like form(), table(), etc
Want results from more Discord servers?
Add your server