Filament Page with Table
Hello, I have a model that has a HasMany(ModaliyYear) relationship and this model(ModaliyYear) has a HasMany(ModalityAttachment) relationship and I created a custom page to list/create the attachments, but I'm not getting it
Error
Code
Filament\Tables\Table::make(): Argument #1 ($livewire) must be of type Filament\Tables\Contracts\HasTable, App\Filament\Resources\ModalityResource\Pages\ModalityAttachments given, called in /var/www/vendor/filament/tables/src/Concerns/InteractsWithTable.php on line 241
Filament\Tables\Table::make(): Argument #1 ($livewire) must be of type Filament\Tables\Contracts\HasTable, App\Filament\Resources\ModalityResource\Pages\ModalityAttachments given, called in /var/www/vendor/filament/tables/src/Concerns/InteractsWithTable.php on line 241
<?php
namespace App\Filament\Resources\ModalityResource\Pages;
use App\Filament\Resources\ModalityResource;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
use Filament\Forms\Components\Builder;
use Filament\Forms\Components\View;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Contracts\HasTable;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Table;
class ModalityAttachments extends Page implements HasTable
{
use InteractsWithRecord, InteractsWithTable;
protected static string $resource = ModalityResource::class;
protected static string $view = 'filament.resources.modality-resource.pages.modality-attachments';
public function table(Table $table) : static
{
return $table
->columns([
TextColumn::make('year')
]);
}
public function mount(int | string $modality, int | string $record): void
{
$this->record = $this->resolveRecord($record);
}
}
<?php
namespace App\Filament\Resources\ModalityResource\Pages;
use App\Filament\Resources\ModalityResource;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
use Filament\Forms\Components\Builder;
use Filament\Forms\Components\View;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Contracts\HasTable;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Table;
class ModalityAttachments extends Page implements HasTable
{
use InteractsWithRecord, InteractsWithTable;
protected static string $resource = ModalityResource::class;
protected static string $view = 'filament.resources.modality-resource.pages.modality-attachments';
public function table(Table $table) : static
{
return $table
->columns([
TextColumn::make('year')
]);
}
public function mount(int | string $modality, int | string $record): void
{
$this->record = $this->resolveRecord($record);
}
}
1 Reply
up
att
Cannot assign Illuminate\Database\Eloquent\Builder to property App\Filament\Resources\ModalityResource\Pages\ModalityAttachments::$record of type Illuminate\Database\Eloquent\Model|string|int|null
<?php
namespace App\Filament\Resources\ModalityResource\Pages;
use App\Filament\Resources\ModalityResource;
use App\Models\ModalityAttachment;
use App\Models\ModalityYear;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
use Filament\Forms\Components\Builder;
use Filament\Forms\Components\View;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Contracts\HasTable;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable as ContractsHasTable;
use Filament\Tables\Table;
class ModalityAttachments extends Page implements ContractsHasTable
{
use InteractsWithRecord, InteractsWithTable;
protected static ?string $model = ModalityAttachment::class;
protected static string $resource = ModalityResource::class;
protected static string $view = 'filament.resources.modality-resource.pages.modality-attachments';
public function mount(int | string $modality, int | string $record): void
{
$this->record = ModalityAttachment::where('modality_year_id', $record);
}
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
]);
}
}
<?php
namespace App\Filament\Resources\ModalityResource\Pages;
use App\Filament\Resources\ModalityResource;
use App\Models\ModalityAttachment;
use App\Models\ModalityYear;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
use Filament\Forms\Components\Builder;
use Filament\Forms\Components\View;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Contracts\HasTable;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable as ContractsHasTable;
use Filament\Tables\Table;
class ModalityAttachments extends Page implements ContractsHasTable
{
use InteractsWithRecord, InteractsWithTable;
protected static ?string $model = ModalityAttachment::class;
protected static string $resource = ModalityResource::class;
protected static string $view = 'filament.resources.modality-resource.pages.modality-attachments';
public function mount(int | string $modality, int | string $record): void
{
$this->record = ModalityAttachment::where('modality_year_id', $record);
}
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
]);
}
}