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'),
        ];
    }


Nested Resource
    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(),
            ]);
    }
Solution
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'),
    ];
}
Was this page helpful?