F
Filament6mo ago
Glebka

Filament 3 custom view page for relation manager class

Hi, I searched for a couple of hours and I still can't find information about how to create a custom page view, or just a view page, instead of a model view on a relation in Filament 3. I have created a resource and a relation (table under a resource record), but the only option is to create a modal view. I need a full page view. Can you help me or at least give me some tips? Can I use infolist() and getPages() methods in a RelationManager? Maybe I need to call some Action class, create a custom view and custom route,or is there a terminal command that allows creating a full page view for a RelationManager? Thanks!
19 Replies
krekas
krekas6mo ago
If I understand correctly you want a view page for the record in the relation manager? Just like resources have?
Glebka
GlebkaOP6mo ago
yes, but for relation manager. Relation manager has only modal, not a view page
Glebka
GlebkaOP6mo ago
i dont really understand, how it is working. relationManager table beggining:
return $table
->recordUrl(
fn (Model $record): string => route('resource.view', ['resource' => $record->id]),
)
return $table
->recordUrl(
fn (Model $record): string => route('resource.view', ['resource' => $record->id]),
)
, route:
Route::get('/learning-categories/resource/{resource}/view', ViewCustomLearningResource::class)->name('resource.view');
Route::get('/learning-categories/resource/{resource}/view', ViewCustomLearningResource::class)->name('resource.view');
and finally custom page:
class ViewCustomLearningResource extends Page
{
use InteractsWithRecord;

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

protected static string $view = 'filament.resources.learning-category-resource.pages.view-custom-learning-resource';
}
class ViewCustomLearningResource extends Page
{
use InteractsWithRecord;

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

protected static string $view = 'filament.resources.learning-category-resource.pages.view-custom-learning-resource';
}
with view:
<x-filament-panels::page>
test
</x-filament-panels::page>
<x-filament-panels::page>
test
</x-filament-panels::page>
, i am receving error: Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class App\Filament\Resources\LearningCategoryResource\Pages\ViewCustomLearningResource i wanted to create a button named view (with icon) to have a behavior like a make filament resource --view parameter, which will create view with getPages() route, i can write a function getPages() with all necessary routes but i dont know how to connect Actions like ViewAction to the getPages() function. Maybe you know how to do that?
krekas
krekas6mo ago
why are you creating a route for custom filament page?
Glebka
GlebkaOP6mo ago
or maybe i need to go outside of filament available functionallity and create route, controller and so on because if i wont create a route it will show me an error that this route doesnt exists
krekas
krekas6mo ago
filament creates route automatically
Glebka
GlebkaOP6mo ago
wait a minute, i will try again
krekas
krekas6mo ago
case 3
Glebka
GlebkaOP6mo ago
yea, if i remove route form web.php it will give me an error, error: Route [resource.view] not defined.
krekas
krekas6mo ago
filament doesn't name routes like that... access route by calling getUrl() method on your page class
Glebka
GlebkaOP6mo ago
if you can, we can go to call for 5 minutes
krekas
krekas6mo ago
no
Glebka
GlebkaOP6mo ago
table beginning:
return $table
->recordUrl(ViewCustomLearningResource::getUrl('resource'))
return $table
->recordUrl(ViewCustomLearningResource::getUrl('resource'))
and getPages():
public static function getPages(): array
{
return [
'resource' => ViewCustomLearningResource::route('/resource'),
];
}
public static function getPages(): array
{
return [
'resource' => ViewCustomLearningResource::route('/resource'),
];
}
, i thought that i did everything correctly but it says that "Expected type 'array'. Found 'string'" error is in table beginning
krekas
krekas6mo ago
something off about what you do. getPages() is in a resource?
Glebka
GlebkaOP6mo ago
no, it is in a relationManager, i need to make custom view page (not a modal, by default it is a modal for relationManag) for a relationManager. Do i still need to put custom view page in a resource?
krekas
krekas6mo ago
you only create a custom page and call it in the table
Glebka
GlebkaOP6mo ago
i can put a custom page in a parent resource but how to call it from relation?
Want results from more Discord servers?
Add your server