简体   繁体   English

LARAVEL:同名扰乱link_to_route的POST和GET路由

[英]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()

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

It creates this link: 它创建此链接:

http://my.site/prefix/list?page=5&size=12 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 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? 我该如何解决?

您可以尝试仅更改路由文件中的路由顺序,以便获得get的最后一个,并出于link_to_route()的目的而覆盖发布内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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