Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MethodNotAllowedHttpException在RouteCollection.php第218:4行_Php_Laravel 5.3 - Fatal编程技术网

MethodNotAllowedHttpException在RouteCollection.php第218:4行

MethodNotAllowedHttpException在RouteCollection.php第218:4行,php,laravel-5.3,Php,Laravel 5.3,在laravel中提交表单时,我将获得MethodNotAllowedHttpException Html文件 <form method="POST" action="/cards/{{$card->id}}/notes"> <input name="_token" type="hidden" value="{{ csrf_token() }}"/> <textarea name="body" class="form-control">&

在laravel中提交表单时,我将获得MethodNotAllowedHttpException

Html文件

<form method="POST" action="/cards/{{$card->id}}/notes">
    <input name="_token" type="hidden" value="{{ csrf_token() }}"/>
    <textarea name="body" class="form-control"></textarea>
    <button type="submit">Add Note</button>
</form>
NotesController.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;

class NotesController extends Controller
{
    public function store()
    {
        return request()->all();
    }
}

确保你没有路线,比如说一个
route::post
,其参数位于你试图点击的路线前面

例如:

Route::post('{something}', 'SomethingController@index');
Route::post('cards/{card}/notes', 'NotesController@store');
在这种情况下,无论您尝试发送什么到卡片路由,它都会命中
something
路由,因为
{something}
正在拦截
卡片作为有效参数,并触发
SomethingController

something
路由放在cards路由下面,它应该可以工作。

MethodNotAllowedHttpException
在未找到匹配路由(方法和URI)但找到具有匹配URI但不匹配方法的路由时抛出

在您的例子中,我想问题是因为路由和控制器之间的URI参数不同

您可以尝试以下两种选择:

  • 从路由中删除参数:
  • 路线::邮寄('卡片/便笺','NotesController@store');
  • 将参数添加到控制器:
  • 公共功能商店($卡) { 返回请求()->all(); }
    我试图解决流明的这个错误,花了我相当多的时间来解决这个问题。 问题在于拉威尔本身

    有时,如果您有另一条路径,如GET device/{variable},laravel会在第一条路径中停止

    因此,您需要做的是将路由
    POST device
    更改为
    POST device/add


    您能显示生成的html代码吗?非常感谢,两种解决方案都运行良好:-)
    Route::post('{something}', 'SomethingController@index');
    Route::post('cards/{card}/notes', 'NotesController@store');
    
    Route::post('cards/notes','NotesController@store'); public function store($card) { return request()->all(); }