drpfu51608120170 2015-07-09 20:46
浏览 45

由laravel自动添加的表单操作URL中的奇怪段

I have this form:

{!!Form::open(['route'=>'fastsearch.show'])!!}

In routes.php I have:

Route::resource('fastsearch','SearchController');

And in SearchController i have a method show() that sends the return to a view called fastsearch (which is fastsearch.blade.php)

If I look into the source of the page where the form is, I see this:

<form method="POST" action="http://localhost:8000/fastsearch/%7Bfastsearch%7D" accept-charset="UTF-8"><input name="_token" type="hidden" value="hLcSkGk2p5XfTkFEv2pwGgcVQB18vHQIGMpOVGpM">

If I put some data in the form and click Submit, I get this error:

MethodNotAllowedHttpException in RouteCollection.php line 201:

My question is why the extra segment in the action URL (this one: /%7Bfastsearch%7D). Is something wrong with the routes ?

(Just to give you all the details, this a general search form that lies on almost every page in order to allow the users to run a quick search from almost every page they might be at that time. So it doesn’t matter if you’re on Home page or on /Home/Subpage/SubSubPage{wildcard}{wildcard} you can still see the form and use it)

  • 写回答

1条回答 默认 最新

  • duanmanmian7589 2015-07-09 21:06
    关注

    You're trying to send a post request to a route expecting a get request.

    Change:

    {!! Form::open(['route'=>'fastsearch.show']) !!}
    

    To:

    {!! Form::open(['route'=>'fastsearch.index']) !!}
    

    Where index is the name of the action you wish to receive the post request.

    You're probably better off using specific named routes for this though.

    Route::post('fastsearch', [
        'as' => 'fastsearch.search', 'uses' => 'SearchController@search'
    ]);
    

    Take a look at http://laravel.com/docs/5.1/controllers#restful-resource-controllers for more info on resource controllers and http://laravel.com/docs/5.1/routing#named-routes for more on named routes.

    You can also use ./artisan route:list for a list of existing routes.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?