【问题标题】:Laravel : Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No messageLaravel : Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException 没有消息
【发布时间】:2019-04-11 00:34:33
【问题描述】:

请帮忙。我无法创建新对象。 这是将创建绘画的形式。 当我打开网站时,它显示 MethodNotAllowedHttpException 并且没有消息。

在 web.php(路由)中

Route::post('store','PaintingController@store');

在控制器中

        $last_line = DB::table('art_objs')->orderBy('Id_no', 'DESC')->first();
        $last = $last_line->Id_no;

        $art_objs = new Art_obj(
            ['Artist' => $request->get('Artist'),
            'Year' => $request->get('Year'),
            'Title' => $request->get('Title'),
            'Description' => $request->get('Description'),
            'Origin' => $request->get('Origin'),
            'Epoch' => $request->get('Epoch'),
            'Type_of_art'=>'1',
            'Type_of_coll'=>$request->input('Type_Coll'),
        ]);
        $art_objs->save();

在刀片中

<form method="post" action="store">  {{csrf_field()}} 
                <div class="form-group">
                    <label> Title: </label> <input type="text" name="Title" class="form-control" placeholder="Title"/> 
                </div>
                <div class="form-group">
                    <label> Artist: </label> <input type="text" name="Artist" class="form-control" placeholder="Artist" /> 
                </div>
                <div class="form-group">
                    <label> Year: </label> <input type="text" name="Year" class="form-control" placeholder="Year"/> 
                </div>
                <div class="form-group">
                    <label> Origin: </label> <input type="text" name="Origin" class="form-control" placeholder="Origin"/> 
                </div>
                <div class="form-group">
                    <label> Epoch: </label> <input type="text" name="Epoch" class="form-control" placeholder="Epoch"/> 
                </div>
                <div class="form-group">
                    <label> Description: </label> <textarea name="Description" class="form-control" rows="5" placeholder="description"></textarea> 
                </div>
                <div class="form-group">
                <label> Paint type: </label><input type="text" name="Paint_type" class="form-control" placeholder="Paint type"/> 
                </div>
                <div class="form-group">
                <label> Drawn on: </label><input type="text" name="Drawn_on" class="form-control" placeholder="Drawn on" /> 
                </div>
                <div class="form-group">
                <label> Style: </label><input type="text" name="Style" class="form-control" placeholder="Style"/> 
                <div class="form-group"> 
                    <input type="submit" class="btn btn-primary" value="CREATE" /> 
                </div>
                <input type="hidden" name="_method" value="PATCH" /> 
            </form>

【问题讨论】:

  • 你能发布php artisan route:list输出吗?
  • MethodNotAllowedHttpException 表示找不到正确方法的路由。在您的表单 (action="/store") 中存储之前添加一个斜杠,这样它就不会尝试使用子目录路由。
  • 我在帖子中添加了php artisan route:list 输出。

标签: php laravel


【解决方案1】:

您的url 应该是/painting 而不是store。请尝试:

<form method="post" action="/painting"> 

【讨论】:

    【解决方案2】:

    从您的表单中删除以下内容:

    <input type="hidden" name="_method" value="PATCH" />
    

    【讨论】:

    • 没问题。很高兴能提供帮助。
    【解决方案3】:

    您使用了 PATCH 方法,那么您应该将 路由 更改为:

    Route::patch('store','PaintingController@store');
    

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 2018-03-25
      • 1970-01-01
      • 2020-06-22
      • 2019-07-01
      • 2018-09-06
      • 2020-01-01
      • 1970-01-01
      • 2019-01-06
      相关资源
      最近更新 更多