Camilo Camilo - 3 years ago 158
PHP Question

Alias for a route with a fixed parameter value

I have this route:

Route::get('/MyModel/{id}', 'MyModel@show');

The method
accepts a parameter called
and I want to setup an alias for
so it's accesible from

I already tried a few combinations, like:

Route::get('/MyCustomURL', ['uses' => 'MyModel@show', 'id' => 1]);

But I keep getting missing required argument error for method

Is there a clean way to achieve this in Laravel?

Answer Source

In same controller (in your case MyModel ?) you should create one new method:

public function showAliased()
   return $this->show(1);

and now you can define your aliased route like so:

Route::get('/MyCustomURL', 'MyModel@showAliased');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download