You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The route() helper doesn't account for the Laravel 7 way of specifying a custom route model binding key inside the route parameter when passing a Model to use implicit binding. It will generate the URL with ID's as parameters instead of the expected column (like a slug).
Steps To Reproduce:
Create a route like this:
Route::get('/profile/{user:slug}', function (User $user) {
return $user;
})->name('profile');
Try to generate a URI using the route() helper: route('profile, $user)
Inspect/view the given URI, it should look something like: https://app.test/profile/1 instead of expected: https://app.test/profile/@johndoe (assuming the slug is @johndoe)
The text was updated successfully, but these errors were encountered:
@driesvints I tried.. I got it working until I found out that my fix was not compatible with explicitly passing the parameter value (so passing $user->slug instead of $user as route() argument). I will link my commit, maybe someone can use it as inspiration: elbojoloco@d26bec6
Edit:
I'll elaborate a bit more on the problem after my fix.
In this image you can see the first bindingField "lucas" being the value that is passed explicitly. The second bindingField is a Post model, because it is passed implicitly. The formatParameterKeys() method in my commit only pulls values from the bindingFields array if the respective param is an instance of UrlRoutable, which is only true for the Post model. As a result the {post} param will try to use the "user" (first bindingField being pulled in this case) key and value "name" to find its route binding key, which will fail and result in it not being bound at all.
Description:
The
route()
helper doesn't account for the Laravel 7 way of specifying a custom route model binding key inside the route parameter when passing a Model to use implicit binding. It will generate the URL with ID's as parameters instead of the expected column (like a slug).Steps To Reproduce:
route()
helper:route('profile, $user)
https://app.test/profile/1
instead of expected:https://app.test/profile/@johndoe
(assuming theslug
is@johndoe
)The text was updated successfully, but these errors were encountered: