简体   繁体   中英

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM