Opening related resource in its own page

Hi! New filament user here. Issue: I have a SoftwareResource and a SoftwareVersionResource. Relation is Software hasMany SoftwareVersions. I want the SoftwareRelations Manager table on the SoftwareResource to open the related model (SoftwareVersions) in its own page but it opens it in a modal. What I tried: Added a View action in the relations manager Error: No error. Just unaware how to do it.
10 Replies
Lift_Kara_De
Lift_Kara_DeOP5mo ago
public static function infolist(Infolist $infolist): Infolist {
return $infolist
->schema([
Section::make()->schema([
TextEntry::make('id')->label('ID'),
TextEntry::make('name')->label('Name'),
}

public static function form(Form $form): Form
{
return $form;
}

public static function table(Table $table): Table
{
return $table
->columns([
// TextColumn::make('id')->label('ID'),

TextColumn::make('created_at')->label('Created At')
->getStateUsing(function ($record) {
return Carbon::parse($record->created_at);
}),
//updated_at
TextColumn::make('updated_at')->label('Updated At')
->getStateUsing(function ($record) {
return Carbon::parse($record->updated_at);
}),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
RelationManagers\VersionsRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListSoftwares::route('/'),
'create' => Pages\CreateSoftware::route('/create'),
'view' => Pages\ViewSoftware::route('/{record}'),
'edit' => Pages\EditSoftware::route('/{record}/edit'),
];
}
}
public static function infolist(Infolist $infolist): Infolist {
return $infolist
->schema([
Section::make()->schema([
TextEntry::make('id')->label('ID'),
TextEntry::make('name')->label('Name'),
}

public static function form(Form $form): Form
{
return $form;
}

public static function table(Table $table): Table
{
return $table
->columns([
// TextColumn::make('id')->label('ID'),

TextColumn::make('created_at')->label('Created At')
->getStateUsing(function ($record) {
return Carbon::parse($record->created_at);
}),
//updated_at
TextColumn::make('updated_at')->label('Updated At')
->getStateUsing(function ($record) {
return Carbon::parse($record->updated_at);
}),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
RelationManagers\VersionsRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListSoftwares::route('/'),
'create' => Pages\CreateSoftware::route('/create'),
'view' => Pages\ViewSoftware::route('/{record}'),
'edit' => Pages\EditSoftware::route('/{record}/edit'),
];
}
}
<?php

namespace App\Filament\Resources\SoftwareResource\RelationManagers;


class VersionsRelationManager extends RelationManager {
protected static string $relationship = 'versions';

public function infolist(Infolist $infolist): Infolist {
return $infolist
->schema([
Section::make()->schema([
TextEntry::make('id')->label('ID'),
TextEntry::make('version')->label('Version'),
TextEntry::make('status')->label('Status')
->formatStateUsing(fn($state) => ucfirst($state)),
])
]);
}
public function form(Form $form): Form {
return $form;
}

public function table(Table $table): Table {
return $table
->recordTitleAttribute('id')
->columns([
TextColumn::make('id'),
TextColumn::make('version')->label('Version'),
TextColumn::make('status')->label('Status')
->formatStateUsing(fn($state) => ucfirst($state)),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
<?php

namespace App\Filament\Resources\SoftwareResource\RelationManagers;


class VersionsRelationManager extends RelationManager {
protected static string $relationship = 'versions';

public function infolist(Infolist $infolist): Infolist {
return $infolist
->schema([
Section::make()->schema([
TextEntry::make('id')->label('ID'),
TextEntry::make('version')->label('Version'),
TextEntry::make('status')->label('Status')
->formatStateUsing(fn($state) => ucfirst($state)),
])
]);
}
public function form(Form $form): Form {
return $form;
}

public function table(Table $table): Table {
return $table
->recordTitleAttribute('id')
->columns([
TextColumn::make('id'),
TextColumn::make('version')->label('Version'),
TextColumn::make('status')->label('Status')
->formatStateUsing(fn($state) => ucfirst($state)),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
Dennis Koch
Dennis Koch5mo ago
Currently Filament doesn't support nested resources. There are some plugins that try to solve this like: #guava-nested-resourcesI think V4 will add support for it
Lift_Kara_De
Lift_Kara_DeOP5mo ago
@Dennis Koch Thanks! I don't think mine is a case of nested resources. I have a Software Resource which hasMany SoftwareVersions. My issue is at the UI level, where adding a relationManager as a table will list out the SoftwareVersions on the Software page but clicking it only shows SoftwareVersion info in a modal and not in its own page
Dennis Koch
Dennis Koch5mo ago
That’s exactly what nested resources are. Another edit page nested under the first edit page instead of a modal. You could also overwrite the EditAction on the relation manager to just link to your software version but then you loose the hierarchy
Lift_Kara_De
Lift_Kara_DeOP5mo ago
I don't require them on the edit page but rather on the view page. Here's the actual thing. On clicking on the "version" it shows the details in a modal. I just need it to open in a new page. Plugin hasMany Versions
Raizo
Raizo5mo ago
you can try this @vipul on your case you will have to change the recordUrl action of your table.
No description
Lift_Kara_De
Lift_Kara_DeOP5mo ago
This look like the thing to do. Surprising why we can't easily switch between modal and view page like it is done in resources quite easily. Thanks a lot!
Dennis Koch
Dennis Koch5mo ago
It's not that commong as you think, because you lose the hierarchy. Can't you just add ->url(YourResource::getUrl('create') to the action? Not sure what's harder about this than in resources?
Lift_Kara_De
Lift_Kara_DeOP5mo ago
Yeah. I udnerstand the point on losing the hierarchy. Maybe i can make the modal much larger to accommodate more data while staying withn the page (https://github.com/filamentphp/filament/discussions/5468) or lose the hierarchy and go to the url anyway.
GitHub
Setting custom width for modal · filamentphp filament · Discussion ...
There is an undocumented method modalWidth() for actions. By default a modal is rather narrow as it usually prompts a simple dialog. But how to set a custom width for a modal when I need a more com...
Lift_Kara_De
Lift_Kara_DeOP5mo ago
This solves it I think Thanks @Dennis Koch and @kingjaypee12
Want results from more Discord servers?
Add your server