Hanik
Hanik

Reputation: 327

How to set default parameter route variable in laravel?

This is my route and I get a status variable but I want to set it up so that that if the status does not come then it must has a default parameter.

Route::get('/list/{status?}', [
    'as' => 'entegra.gg.p.list',
    'uses' => 'ggController@ggList'
]);

I want to set the default parameter for status variable. How can I do that ?

I set the parameter like this but I need to set up a default parameter:

<li><a href="{{ route('entegra.gg.p.list', ['status' => 'A']) }}">@lang('gg\index.sales.A')</a></li>

Upvotes: 1

Views: 654

Answers (1)

Sayantan Das
Sayantan Das

Reputation: 1641

You can set that in your method.

public function ggList($status = "default") {
    // do your magic...
}

If anything comes from the url, it will be overwritten.

Upvotes: 2

Related Questions