有趣的故事,我的Laravel路线没有使用方法欺骗......我有以下内容:
<form action="{{route('admin.page.update', $page->id)}}" method="POST" accept-charset="UTF-8">
{{ method_field('PUT') }}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="page[name]">
<input type="submit" value="submit">
</form>
这表现为:
<form action="http://ULTRA_HIDDEN_DOMAIN.dev/admin/page/9" method="POST" accept-charset="UTF-8">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="ULTRA_HIDDEN_KEY">
<input type="text" name="page[name]">
<input type="submit" value="submit">
</form>
但是当我点击提交按钮时,我在Chrome网络上得到以下答案:
Request URL:http://ULTRA_HIDDEN_DOMAIN.dev/admin/page/9
Request Method:POST
Status Code:302 Found
当我php artisan route:list
时,我将其列出:
+--------+-----------+------------------------------------+------------------------------------+-------------------------------------------------------------------+----------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+------------------------------------+------------------------------------+-------------------------------------------------------------------+----------------+
| | GET|HEAD | admin/page | admin.page.index | App\Http\Controllers\Admin\PageController@index | web,auth.admin |
| | POST | admin/page | admin.page.store | App\Http\Controllers\Admin\PageController@store | web,auth.admin |
| | GET|HEAD | admin/page/create | admin.page.create | App\Http\Controllers\Admin\PageController@create | web,auth.admin |
| | GET|HEAD | admin/page/{page} | admin.page.show | App\Http\Controllers\Admin\PageController@show | web,auth.admin |
| | PUT|PATCH | admin/page/{page} | admin.page.update | App\Http\Controllers\Admin\PageController@update | web,auth.admin |
| | DELETE | admin/page/{page} | admin.page.destroy | App\Http\Controllers\Admin\PageController@destroy | web,auth.admin |
| | GET|HEAD | admin/page/{page}/edit | admin.page.edit | App\Http\Controllers\Admin\PageController@edit | web,auth.admin |
+--------+-----------+------------------------------------+------------------------------------+-------------------------------------------------------------------+----------------+
使用Route::resource('page', 'PageController');
创建路线。
关于为什么欺骗方法不起作用的任何想法?
答案 0 :(得分:1)
Http中的状态代码302用于重定向,所以我想,这个请求很好,但也许它无法通过你设置的一些中间件,所以不得不重定向到其他地方。
例如,您的PUT路由需要用户登录才能更新该记录,并且您没有登录以便中间件“重定向”#39;你到了302代码的登录页面。