glhd / gretel

Laravel breadcrumbs right out of a fairy tale
MIT License
243 stars 16 forks source link

Dash in a resource route name breaks Route Model binding #12

Open butcherman opened 1 year ago

butcherman commented 1 year ago

Describe the bug When I have a resource route that has a dash in the name, route/model binding gets broken and an error "Missing required parameter for [Route....]"

What version does this affect?

To Reproduce Setup a simple Resource Controller using Resource Breadcrumbs. Ex: Route::resource('some-route', SomeRouteController::class)->breadcrumbs(function(ResourceBreadcrumbs $breadcrumbs) { $breadcrumbs->index('Index Rte')->show('Show Rte')->edit('Edit Rte'); }

When trying to visit the Edit or Show routes and you will get the missing required parameter error. Changing the - to an underscore will correct the error. Separating the resource route into individual routes will also correct the error.

Expected behavior I use dashes in my route names on a regular basis as they are easy to read and match up with Laravel's slug method

raphaelbeckmann commented 1 year ago

I have the same problem. I also found out that Gretel is converting the kebab case resource identifier ("some-route") to snake case in the model identifier variable ($some_route) instead of camel case ($someRoute). That should be fixed as well.

inxilpro commented 1 year ago

Can you explain why this test doesn't cover the case you're describing?

butcherman commented 1 year ago

In the test you provided, you are using Route Model Binding. In my examples I am not. In my use case, I use it where I can, but in this case I search for the model based on if the user input a slug (string) or the ID (int) of the model. I need to search two columns so Route Model Binding does not work well for me.