Skip to content

Conversation

@LordSimal
Copy link
Contributor

@LordSimal LordSimal commented Feb 7, 2026

Closes #8188

$routes->scope('/api', function (RouteBuilder $routes) {
$routes->resources('Articles', function (RouteBuilder $routes) {
$routes->resources('Comments', ['prefix' => 'Articles']);
$routes->resources('Comments', options: ['prefix' => 'Articles']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always recommend named params for route building methods or only in certain situations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always using named params in e.g. code keeps things consistent and more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean we should also add named params for 1st and 2nd param calls on all RouteBuilder calls in the docs?

$routes->scope('/api', function (RouteBuilder $routes) {
$routes->resources('Articles', function (RouteBuilder $routes) {
$routes->resources('Comments', ['prefix' => 'Articles']);
$routes->resources('Comments', options: ['prefix' => 'Articles']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always using named params in e.g. code keeps things consistent and more readable.

@LordSimal
Copy link
Contributor Author

@ADmad this what you had in mind?

@ADmad
Copy link
Member

ADmad commented Feb 10, 2026

@ADmad this what you had in mind?

Don't like the use of named arg for the 1st argument :) Sorry for not being clear earlier, I meant to use them for 2nd/3rd args because of the swapping of the args done in 6.x.

Your changes do highlight an inconsistency though. For RouterBuilder::connect() the 1st arg is called route, while for RouterBuilder::get() (and other RESTful shortcuts) it is called template. Should sync the argument names between the methods?

RouteBuilder::connect() also accepts a Route instance as 1st argument but in this case the $defaults argument is ignored (unless I am misreading the code). I am wondering if we should add a separate method RouterBuilder::add(Route $route, array $options = []) and make the 1st arg of RouteBuilder::connect() string only. Then we can rename it to template.

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.

3 participants