getResource method does not exist

I'm trying to use a Page class and the InteractsWithRecord trait, but I'm getting an error saying the getResource method doesn't exist. What am I doing wrong? Do I have to define this method in my class? The docs didn't mention anything about that.
class Detail extends Page
{
use InteractsWithRecord;

protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list';

protected static string $view = 'filament.app.pages.location.detail';

protected static ?string $title = 'Details';

protected static ?string $slug = 'location/{record}/detail';

protected static bool $shouldRegisterNavigation = false;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
}

...
}
class Detail extends Page
{
use InteractsWithRecord;

protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list';

protected static string $view = 'filament.app.pages.location.detail';

protected static ?string $title = 'Details';

protected static ?string $slug = 'location/{record}/detail';

protected static bool $shouldRegisterNavigation = false;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
}

...
}
3 Replies
Jon Mason
Jon MasonOP9mo ago
I think I was extending the wrong Page class. I fixed that, but now I'm getting Filament\Resources\Pages\Page::$resource must not be accessed before initialization It's coming from this sidebar class I have that basically only shows menu items once a location is selected:
$items[] = NavigationItem::make('Details')
->icon('heroicon-o-clipboard-document-list')
->group($selectedLocation->name)
->isActiveWhen(fn (): bool => request()->routeIs("filament.app.pages.location.{record}.detail"))
->url(Detail::getUrl(['record' => $selectedLocation->id]));
$items[] = NavigationItem::make('Details')
->icon('heroicon-o-clipboard-document-list')
->group($selectedLocation->name)
->isActiveWhen(fn (): bool => request()->routeIs("filament.app.pages.location.{record}.detail"))
->url(Detail::getUrl(['record' => $selectedLocation->id]));
It doesn't like that last url() bit.
mvenghaus
mvenghaus9mo ago
try wrapping it in a function
Jon Mason
Jon MasonOP9mo ago
Ok, It seems that extending Filament/Resources/Pages/Page makes the initial issue work, but then getUrl was giving an error saying the first parameter was a string and was expecting an array. Changing it to extend Filament/Pages/Page fixes the getUrl issue, but then I get the getResource method doesnt' exist again. So lost..
Want results from more Discord servers?
Add your server