F
Filament12mo ago
Bloom

Declaration of Filament\Actions\Concerns\InteractsWithRecord::getModel()

i am using InteractsWithRecord on custom page and i get the above error, can anyone help me with it?
8 Replies
ChesterS
ChesterS12mo ago
is that the complete error?
Np
Np12mo ago
Send code snippet also @Bloom
Bloom
BloomOP12mo ago
Declaration of Filament\Actions\Concerns\InteractsWithRecord::getModel(): ?string must be compatible with Filament\Resources\Pages\Page::getModel(): string
Declaration of Filament\Actions\Concerns\InteractsWithRecord::getModel(): ?string must be compatible with Filament\Resources\Pages\Page::getModel(): string
This is the complete error given
class SupplierDetail extends Page implements HasRecord
{
protected static string $view = 'filament.resources.supplier-resource.pages.supplier-detail';

use InteractsWithRecord;

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

static::authorizeResourceAccess();
}
class SupplierDetail extends Page implements HasRecord
{
protected static string $view = 'filament.resources.supplier-resource.pages.supplier-detail';

use InteractsWithRecord;

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

static::authorizeResourceAccess();
}
This is the custom page on which i am trying to use record send from an action and below is the action that route to the custom page
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Action::make('supplier-details')
->url(fn (Supplier $record):string => static::getUrl('supplier-details',['record' => $record])),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Action::make('supplier-details')
->url(fn (Supplier $record):string => static::getUrl('supplier-details',['record' => $record])),
])
public static function getPages(): array
{
return [
'index' => Pages\ManageSuppliers::route('/'),
'supplier-details' => Pages\SupplierDetail::route('/{record}/supplier-details'),

];
}
public static function getPages(): array
{
return [
'index' => Pages\ManageSuppliers::route('/'),
'supplier-details' => Pages\SupplierDetail::route('/{record}/supplier-details'),

];
}
DrByte
DrByte12mo ago
GitHub
filament/packages/panels/src/Resources/Pages/Page.php at a08bcc7f68...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
GitHub
filament/packages/panels/src/Resources/Resource.php at a08bcc7f6859...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
GitHub
filament/packages/actions/src/Concerns/InteractsWithRecord.php at a...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Bloom
BloomOP12mo ago
i have no clue what you are trying to say So i made getModel() not nullable inside InteractsWithRecord
public function getModel(): string
public function getModel(): string
And in my custom page i make it like this
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}
public function resolveRecord($record): ?Supplier
{
return Supplier::query()->where('id', $record)->first();

}
public function table(Table $table): Table
{

return $table
->query(Supplier::query()->where('id', $this->record->id))
->columns([
TextColumn::make('supplier_name'),
TextColumn::make('contact_number'),
TextColumn::make('email'),
TextColumn::make('address')
]);
}
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}
public function resolveRecord($record): ?Supplier
{
return Supplier::query()->where('id', $record)->first();

}
public function table(Table $table): Table
{

return $table
->query(Supplier::query()->where('id', $this->record->id))
->columns([
TextColumn::make('supplier_name'),
TextColumn::make('contact_number'),
TextColumn::make('email'),
TextColumn::make('address')
]);
}
It works but i don't know if it is the right way to achieve, since i am quering multiple times
DrByte
DrByte12mo ago
In part I was pointing out that maybe there's a bug in the trait, because if they're meant to be used together then they should be compatible. So if they're not compatible then maybe it's a bug, or you're including the wrong trait. But I'm surprised more aren't complaining of the same thing. But there are others around here who'd know more than me about doing what you're trying to do.
Bloom
BloomOP12mo ago
Bloom
BloomOP12mo ago
And the way resolveRecord() is explained in the documentaion is quite confusing I hope it doesn't hinder performance
Want results from more Discord servers?
Add your server