F
Filamentβ€’2mo ago
frame

V4 Custom data in a RelationManager

I want one of the tabs of my User's relation tables to use custom data. I assume I need to use a relation manager for that, but how do I use custom data in a relation manager? I tried
class ResultsRelationManager extends RelationManager
{
protected static string $relationship = 'results';

public function table(Table $table): Table
{
return $table
->records(fn (): array => [
['name' => 'Test result']
])
->columns([
TextColumn::make('name'),
]);
}
}
class ResultsRelationManager extends RelationManager
{
protected static string $relationship = 'results';

public function table(Table $table): Table
{
return $table
->records(fn (): array => [
['name' => 'Test result']
])
->columns([
TextColumn::make('name'),
]);
}
}
but I'm getting error
Filament\Resources\RelationManagers\RelationManager::{closure:Filament\Resources\Concerns\InteractsWithRelationshipTable::makeTable():106}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, array given, called in vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 36
Filament\Resources\RelationManagers\RelationManager::{closure:Filament\Resources\Concerns\InteractsWithRelationshipTable::makeTable():106}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, array given, called in vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 36
Solution:
There's not much difference.
Jump to solution
8 Replies
toeknee
toekneeβ€’2mo ago
Going to guess relationmanager tables don't have custom data records support and needs to be a model, since it's classes as a relationship, also you should set keys for the arrays FYI as per the docs.
frame
frameOPβ€’2mo ago
Yes it seems I misunderstood custom data, it doesn't work on a Resource either without using Models. πŸ€” I need to use a custom page instead to be able to render tables with array data, hopefully I can recreate the nice ui of a regular view resource page
toeknee
toekneeβ€’2mo ago
Yeah that makes sense, but you could also create a basic livewire component that renders a table and render that in the form too.
frame
frameOPβ€’2mo ago
I want the custom data table to live in the tabs alongside regular relationmanagers, so I'll have to see if I can find out how the tabs work
No description
frame
frameOPβ€’2mo ago
$records = [
// 1 => ['name' => 'Test result'],
2 => Result::make(['name' => 'Test result'])
];
$records = [
// 1 => ['name' => 'Test result'],
2 => Result::make(['name' => 'Test result'])
];
One last try using a "fake" Model. Unfortunately first option throws Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, array given, while the second throws Argument #1 ($record) must be of type array, App\Models\Result given πŸ˜…
toeknee
toekneeβ€’2mo ago
You'd probaby be better using sushi for this then https://github.com/calebporzio/sushi
GitHub
GitHub - calebporzio/sushi: Eloquent's missing "array" driver.
Eloquent's missing "array" driver. Contribute to calebporzio/sushi development by creating an account on GitHub.
Solution
Dennis Koch
Dennis Kochβ€’2mo ago
There's not much difference.
Dennis Koch
Dennis Kochβ€’2mo ago
Have a look at the ViewPage page() method

Did you find this page helpful?