Skip to content

Conversation

@zachgarwood
Copy link
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

@zachgarwood zachgarwood requested a review from Tofandel October 1, 2025 15:39
@Tofandel
Copy link
Contributor

Tofandel commented Oct 2, 2025

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
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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants