`moduleRoute` - Ensure scalar parameters are wrapped in an array.
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
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?
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:
- https://github.com/area17/twill/blob/3.x/src/Http/Controllers/Admin/FileLibraryController.php#L148
- https://github.com/area17/twill/blob/3.x/src/Models/Media.php#L81
- https://github.com/area17/twill/blob/3.x/src/Repositories/Behaviors/HandleBlocks.php#L460
- https://github.com/area17/twill/blob/3.x/src/Repositories/Behaviors/HandleBlocks.php#L495
- https://github.com/area17/twill/blob/3.x/src/Repositories/Behaviors/HandleBrowsers.php#L208
- https://github.com/area17/twill/blob/3.x/src/Services/Breadcrumbs/NestedBreadcrumbs.php#L78