laravellaravel-5routesnamed-routing

LARAVEL: POST and GET routes with same name scrambling link_to_route


I got these routes:

    Route::get('prefix/list/{page?}/{size?}', ['as' => 'prefix.list', 'uses' => 'MyController@getList']);
    Route::post('prefix/list', ['as' => 'prefix.list', 'uses' => 'MyController@postList']);

When I call link_to_route() like so:

{{ link_to_route('prefix.list', $page, ['page' => $page, 'size' => $size]) }}

It creates this link:

http://my.site/prefix/list?page=5&size=12

But when I remove the post route, it renders correctly this:

http://my.site/prefix/list/5/12

I don't want to change the name of the routes because my system depends on them being the same. How can I solve this?


Solution

  • You could try just changing the order of the routes in your routes file, so that the get one comes last and overrides the post for the purposes of link_to_route().