Skip to content
Advertisement

Alias for a route with a fixed parameter value

I have this route:

JavaScript

The method show() accepts a parameter called id and I want to setup an alias for /MyModel/1 so it’s accesible from /MyCustomURL.

I already tried a few combinations, like:

JavaScript

But I keep getting missing required argument error for method show().

Is there a clean way to achieve this in Laravel?

Advertisement

Answer

In Laravel 5.4 (or maybe earlier) you can use defaults function in your routes file.

Here is example:

JavaScript

In this case you don’t need to add additional method in your controller.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement