V4 Nested Resources

Has anybody started using nested resources in version 4 once I try accessing the nested list I get 404 Parent Resource
protected static ?string $model = ReviewProgram::class;

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->searchable()
->sortable(),
])
->actions([
Action::make('sections')
->authorize(\Auth::user()->can('viewReviewSection', ReviewProgram::class))
->color('success')
->icon('heroicon-m-academic-cap')
->url(
fn ($record):string => ReviewSectionResource::getUrl('index',[
'review-program' => $record,
])
),
])

->recordAction('sections');
}

public static function getPages(): array
{
return [
'index' => Pages\ListReviewPrograms::route('/'),
'edit' => Pages\EditReviewProgram::route('/{record}/edit'),
];
}
protected static ?string $model = ReviewProgram::class;

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->searchable()
->sortable(),
])
->actions([
Action::make('sections')
->authorize(\Auth::user()->can('viewReviewSection', ReviewProgram::class))
->color('success')
->icon('heroicon-m-academic-cap')
->url(
fn ($record):string => ReviewSectionResource::getUrl('index',[
'review-program' => $record,
])
),
])

->recordAction('sections');
}

public static function getPages(): array
{
return [
'index' => Pages\ListReviewPrograms::route('/'),
'edit' => Pages\EditReviewProgram::route('/{record}/edit'),
];
}
Nested Resource
protected static ?string $model = ReviewSection::class;

protected static ?string $parentResource = ReviewProgramResource::class;

public static function getPages(): array
{
return [
'index' => ManageReviewProgramSections::route('/'),
];
}
protected static ?string $model = ReviewSection::class;

protected static ?string $parentResource = ReviewProgramResource::class;

public static function getPages(): array
{
return [
'index' => ManageReviewProgramSections::route('/'),
];
}
ManageReviewProgramSections
protected static string $resource = ReviewSectionResource::class;

protected static string $relationship = 'reviewSections';

protected static ?string $relatedResource = ReviewProgramResource::class;

public function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make(),
]);
}
protected static string $resource = ReviewSectionResource::class;

protected static string $relationship = 'reviewSections';

protected static ?string $relatedResource = ReviewProgramResource::class;

public function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make(),
]);
}
Solution:
I think you should add to it the parent resource ```php public static function getPages(): array {...
Jump to solution
8 Replies
LeandroFerreira
LeandroFerreira5mo ago
To access the nested resource, you will also need a relation manager or relation page
GitHub
filament/docs/03-resources/08-nesting.md at 4.x · filamentphp/fila...
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
Majid Al Zariey
Majid Al ZarieyOP5mo ago
Already registered ManageReviewProgramSections
class ManageReviewProgramSections extends ManageRelatedRecords
{
protected static string $resource = ReviewSectionResource::class;

protected static string $relationship = 'reviewSections';

protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;

protected static ?string $relatedResource = ReviewProgramResource::class;

public function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make(),
]);
}
}
class ManageReviewProgramSections extends ManageRelatedRecords
{
protected static string $resource = ReviewSectionResource::class;

protected static string $relationship = 'reviewSections';

protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;

protected static ?string $relatedResource = ReviewProgramResource::class;

public function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make(),
]);
}
}
The page added to the nested resource
public static function getPages(): array
{
return [
'index' => ManageReviewProgramSections::route('/'),
];
}
public static function getPages(): array
{
return [
'index' => ManageReviewProgramSections::route('/'),
];
}
Solution
LeandroFerreira
LeandroFerreira5mo ago
I think you should add to it the parent resource
public static function getPages(): array
{
return [
'index' => Pages\ListReviewPrograms::route('/'),
'edit' => Pages\EditReviewProgram::route('/{record}/edit'),
'sections' => ManageReviewProgramSections::route('/{record}/sections'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListReviewPrograms::route('/'),
'edit' => Pages\EditReviewProgram::route('/{record}/edit'),
'sections' => ManageReviewProgramSections::route('/{record}/sections'),
];
}
Majid Al Zariey
Majid Al ZarieyOP5mo ago
Still not working the route appears fine in the route:list
No description
LeandroFerreira
LeandroFerreira5mo ago
I recommend reviewing your resources because the N Resource feature works well here
Majid Al Zariey
Majid Al ZarieyOP5mo ago
I will check in a new project and update you.
Majid Al Zariey
Majid Al ZarieyOP5mo ago
GitHub
GitHub - malzariey/nested_resource
Contribute to malzariey/nested_resource development by creating an account on GitHub.
Majid Al Zariey
Majid Al ZarieyOP5mo ago
minimal reproduction after I click the action I get Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class Filament\Resources\Pages\ManageRelatedRecords Happens after clicking the link of the action below Action
Action::make('userItems')
->label('Items')
->icon('heroicon-o-rectangle-stack')
->url(fn ($record) => UserItemResource::getUrl('index',[
'user' => $record,
])),
Action::make('userItems')
->label('Items')
->icon('heroicon-o-rectangle-stack')
->url(fn ($record) => UserItemResource::getUrl('index',[
'user' => $record,
])),
Not sure what I am doing wrong :\ Doesnt appear to work if I define the page in the parent and not in the nested resource ok, it works now,
protected static string $resource = ReviewSectionResource::class;

protected static ?string $relatedResource = ReviewProgramResource::class;
protected static string $resource = ReviewSectionResource::class;

protected static ?string $relatedResource = ReviewProgramResource::class;
needed to switch between these thanks for pointing that out

Did you find this page helpful?