MethodNotAllowedHttpException laravel 5.4

时间:2017-06-14 22:57:22

标签: laravel-5.4

尝试做一个简单的插入,但我在RouteCollection.php(第251行)的RouteCollection-> methodNotAllowed(数组('GET','HEAD','PUT','PATCH','DELETE)中得到此错误MethodNotAllowedHttpException '))在RouteCollection.php(第238行)

这是我在视图中的表单

Bitmap bitmap = BitmapFactory.decodeFile(...); // Here is the "hard work" already done, even if observable below is not subscribed at all.
Observable.just(bitmap);

我的路线

  <form method="post" action="{{route('product.create')}}" class="form-horizontal" enctype="multipart/form-data">
        {!! csrf_field() !!}
        <fieldset>
            <!-- Text input-->
            <div class="form-group">
                <label class="col-md-3 control-label" for="name">Name</label>
                <div class="col-md-9">
                    <input id="name" name="name" type="text" placeholder="Product name" class="form-control input-md">

                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label" for="textarea">Description</label>
                <div class="col-md-9">
                    <textarea class="form-control" id="textarea" name="description"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label" for="size">Size</label>
                <div class="col-md-9">
                    <select class="form-control" id="size">
                        <option selected>Choose size...</option>
                        <option value="small">Small</option>
                        <option value="medium">Medium</option>
                        <option value="larg">Larg</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label" for="category_id">Category</label>
                <div class="col-md-9">
                    <select class="form-control" id="category_id">

                        <option selected>Choose Categories...</option>
                        {{--<option value= "$categories"></option>--}}
                        <option value= "1"> men </option>

                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label" for="image">Image</label>
                <div class="col-md-9">
                    <input id="file" name="image" class="input-file" type="file">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label" for="submit"></label>
                <div class="col-md-9">
                    <button id="submit" name="submit" class="btn btn-primary">Create</button>
                </div>
            </div>

        </fieldset>

    </form>

我的控制器

Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){

Route::get('/' ,function(){
return view('admin.index');
})->name('admin.index');
});
Route::resource('product','ProductsController');
Route::resource('category','CategoriesController');

任何帮助将不胜感激

3 个答案:

答案 0 :(得分:2)

应该是:

action="{{route('product.store')}}"

路由product.create期望GET标头显示注册表单

答案 1 :(得分:0)

我忘记在添加名称之后立即为表单添加名称i get alle field除了image

答案 2 :(得分:0)

我尝试了以上所有答案,但仍然遇到此问题。因此我发现我的模型需要“ fillable”属性:

protected $fillable = ['name', 'status', 'etc','etc2'];

这解决了问题,现在我可以发布/放置/删除。

此外,在我的路线文件中,我只是使用例如:

 Route::resource('user', 'v1\UserController');