Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiple model parameters in routes. #33

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

ricventu
Copy link
Contributor

Hi!

I've enhanced the routing system to support multiple parameters in routes.
Additionally, when dealing with nested controllers, if a parameter is already present in the parent route, it gets filtered out from the child route. This allows developers to specify all parameters directly in the controller method.

For example:

class ModelController
{
    public function edit(User $user, Photo $photo) {}
}

the route is:

model/edit/{user}/{photo}

With nested Controller:

// path: Controllers/PhotosController
class PhotosController
{
    public function show(Photo $photo) {}
}

// path: Controllers/Photos/CommentsController
class CommentsController
{
    public function show(Photo $photo, Comment $comment) {}
}

the route is:

photos/{photo}
photos/{photo}/comments/{comment}

Enhanced route discovery to support multiple model parameters in nested controllers. Updated URI generation logic to account for multiple parameters and adjusted tests to validate the new behavior.
@freekmurze
Copy link
Member

Thank you for this. The tests are failing, could you take a look at that?

@freekmurze freekmurze merged commit bbd1258 into spatie:main Dec 23, 2024
18 of 19 checks passed
@freekmurze
Copy link
Member

Thanks!

@ricventu ricventu deleted the multiple-route-parameters branch December 23, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants