Skip to content

moduleRoute - Ensure scalar parameters are wrapped in an array. - #2781

Merged
ifox merged 4 commits into
area17:3.xfrom
zachgarwood:fix/module-route-helper
May 4, 2026
Merged

moduleRoute - Ensure scalar parameters are wrapped in an array.#2781
ifox merged 4 commits into
area17:3.xfrom
zachgarwood:fix/module-route-helper

Conversation

@zachgarwood

Copy link
Copy Markdown
Contributor

Description

In the moduleRoute helper function, $parameters is allowed to be passed in as an int or a string, in addition to an array; however, the variable is then passed to array_merge without any type conversion, and throws an error.

Related Issues

Fixes #2780

Comment thread src/Helpers/routes_helpers.php Outdated
@zachgarwood
zachgarwood requested a review from Tofandel October 1, 2025 15:39
@Tofandel

Tofandel commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

I do have a comment on this, aren't parameters an associative array, meaning they need a key?

In which case would passing a string or int to parameters which would result in an indexed array be valid?

@zachgarwood

Copy link
Copy Markdown
Contributor Author

I do have a comment on this, aren't parameters an associative array, meaning they need a key?

In which case would passing a string or int to parameters which would result in an indexed array be valid?

If the parameters don't have a string key, they are applied to the URL template after the named params, by position, see Laravel's RouteUrlGenerator::replaceRouteParameters().

So, given a route defined as:
Route::get('/parent/{parentId}/child/{childId}/type/{type}', [Controller::class, 'show')->name('show');
Calling route('show', parameters: ['type' => 'thing', 123, 456]) would generate the url http://domain.com/parent/123/child/456/type/thing.

Getting back to moduleRoute, if we only want to pass parameters as associative arrays, here are the lines we would have to update:

@ifox
ifox merged commit a1ca1ad into area17:3.x May 4, 2026
19 checks passed
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.

The moduleRoute helper function throws an error

3 participants