Custom Page throws error with default code.
What I am trying to do:
Add a custom page.
What I did:
Followed the default instructions on the filamentphp website. https://filamentphp.com/docs/3.x/panels/resources/custom-pages
The command I ran:
art make:filament-page ManageSheets --resource=BinderResource --type=customadded to ManageSheets.php the
use InteractsWithRecord;
line, and the exampled mount entries. See code below.
added a route to my resource file.
'manage' => Pages\ManageSheets::route('/{record}/manage'),added a link which uses the route:
Action::make('Manage') ->url(fn (Binder $record): string => BinderResource::getUrl('manage', ['record' => $record->id])),My issue/the Error: The link resolves, but the ManageSheets.php throws two types of errors. First error: Trait "App\Filament\Binder\Resources\BinderResource\Pages\InteractsWithRecord" not found Second error: App\Filament\Binder\Resources\BinderResource\Pages\ManageSheets::resolveRecord does not exist. I expect the site to load a basic blank page as zero additional customization was done. Here is my page code:
<?php namespace App\Filament\Binder\Resources\BinderResource\Pages; use App\Filament\Binder\Resources\BinderResource; use Filament\Resources\Pages\Page; class ManageSheets extends Page { use InteractsWithRecord; protected static string $resource = BinderResource::class; protected static string $view = 'filament.binder.resources.binder-resource.pages.manage-sheets'; public function mount(int | string $record): void { $this->record = $this->resolveRecord($record); static::authorizeResourceAccess(); } }Did something change is a recent update in which the instructions have not been updated to reflect? am I missing something?
8 Replies
Trait "App\Filament\Binder\Resources\BinderResource\Pages\InteractsWithRecord" not foundYou didn't import the correct namespace for
InteractsWithRecord
, so it's assuming you want it from the class's own namespace.
Probably need: use Filament\Resources\Pages\Concerns\InteractsWithRecord;
@DrByte thank you for the suggestion. I ended up using
use Filament\Forms\Concerns\InteractsWithForms;
as import. Funny thing, the official instruction do not have an import for interactswithrecord.InteractsWithRecord is already included with InteractsWithForm. You just need to include higher up the tree.
I am not for sure how I can go higher up the tree. I was all ready at the root (top?). I hear you when you say that interactswithrecord is already part of interactswithform, yet when I try to use it, I get the error we are talking about. so something has broken or sperated them.
Page is a livewire component so its concerns should be forms, tables etc, not records.
Forms, tables and info lists care about records, pages don’t.
ok, that is good to know. so is there a better way to implement pages with tabs which does concern itself with records? my end goal is to have tabs represent sheets which are part of a binder. when the tab is clicked, then the components or widgets of that sheet are exposed and interacted with.
How are the “sheets” being stored in the database?
You might need a custom livewire component to make this work, if I’m thinking about it in the right way.
sheets have their own table, with a binders having a one to many with the sheets. basically, binders can have many sheets, sheets can only belong to one binder. I use a foreign key "binder_id" on the sheet table to store the relationship. I am thinking I will need another custom live wire component to make this work. I will probably make a "sheet" component which gets the sheet id attribute, then simply have the binder component call the sheet component how ever many times there are sheets.