Skip to content

[5.4] Fixing Model Binding when you have a Route Binding with same name - #18476

Merged
taylorotwell merged 1 commit into
laravel:5.4from
dbpolito:model_and_route_binding
Mar 24, 2017
Merged

[5.4] Fixing Model Binding when you have a Route Binding with same name#18476
taylorotwell merged 1 commit into
laravel:5.4from
dbpolito:model_and_route_binding

Conversation

@dbpolito

Copy link
Copy Markdown
Contributor

When you have a Route Binding with the same compound name of the Model Binding, it colides, for example:

Route::model('foo_bar', FooBarModel::class);
Route::resource('foo-bar', FooBarController::class);

class FooBarController extends Controller {
    public function show(FooBarModel $fooBar) {
    }
}

This happens because at https://github.com/laravel/framework/blob/5.4/src/Illuminate/Routing/ImplicitRouteBinding.php#L21 the parameter is called fooBar and isn't found, but bellow at https://github.com/laravel/framework/blob/5.4/src/Illuminate/Routing/ImplicitRouteBinding.php#L27 it changes the parameter name to foo_bar and at https://github.com/laravel/framework/blob/5.4/src/Illuminate/Routing/ImplicitRouteBinding.php#L32 the parameter value is already a FooBarModel.

The use case is pretty specific, Route and Model Binding with same name AND compound name.

My PR fixes this problem.

@taylorotwell

Copy link
Copy Markdown
Member

Can you describe what you mean by "collide". What error occurs?

@taylorotwell
taylorotwell merged commit 5eb2e6c into laravel:5.4 Mar 24, 2017
@taylorotwell

Copy link
Copy Markdown
Member

Nevermind I recreated it. Thanks.

@GrahamCampbell GrahamCampbell changed the title Fixing Model Binding when you have a Route Binding with same name [5.4] Fixing Model Binding when you have a Route Binding with same name Mar 29, 2017
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.

2 participants