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

[10.x] Do not mutate underlying values on redirect #46281

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Feb 27, 2023

Fixes #46273

Due of the use of toArray the underlying values, e.g. an Eloquent model, are also cast to an array if they implement the Arrayable contract.

This means that the following will fail, as the explicit route model binding will return an eloquent model and the model will then be cast to an array and finally the array will be used as the "user" parameter.

Route::redirect('users/{user}', 'users/{user}/overview');

Route::get('users/{user}/overview', fn () => 'foo');

Route::bind('user', fn ($id) => User::findOrFail($id));

This should not be a breaking change, as the router can not handle parameters that are an array. The following will throw an "array to string exception"...

Route::redirect('users/{user}', 'users/{user}/overview');

Route::get('users/{user}/overview', fn () => 'foo');

// bind to an array
Route::bind('user', fn ($id) => [$id]);

@Propaganistas
Copy link
Contributor

Seems like an elegant fix for my bug report. Thanks!

@taylorotwell taylorotwell merged commit 5e8f9b0 into laravel:10.x Feb 27, 2023
@timacdonald timacdonald deleted the model-redirect branch February 27, 2023 21:26
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.

Parameters in Route::redirect() are handled differently for implicit/explicit bindings
3 participants