【问题标题】:validation inputs throw a The GET method is not supported for this route. Supported methods: POST. error验证输入 throw a 此路由不支持 GET 方法。支持的方法:POST。错误
【发布时间】:2019-12-24 04:04:39
【问题描述】:

我正在尝试验证输入字段,但是当我使用验证规则时,它会抛出:The GET method is not supported for this route. Supported methods: POST. 错误。

这是我的控制器

public function delivery(Request $request)
{
    $request->validate([
        'code' =>'required|numeric|size:4'
    ]);

    return view('frontEnd.orderInfo');
}

这是路线:

Route::post('/delivery','orderController@delivery');

这是风景

<form id="loginform" action="{{url('delivery')}}" class="form-horizontal" method="post" role="form" enctype="multipart/form-data">
    @if ($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif 
    {{method_field('POST')}}
    {{ csrf_field() }}   
    <div style="margin-bottom: 25px" class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
        <input  type="password" class="form-control" name="code" value="" placeholder="enter code.">
    </div>    
    <div style="margin-top:10px" class="form-group">
        <!-- Button -->
        <div class="col-sm-12 controls">
            <input type="submit" class="btn btn-success" value="submit"/>          
        </div>
    </div>  
</form>

【问题讨论】:

  • 请显示路线和显示视图的功能

标签: laravel laravel-5 laravel-5.8 laravel-validation


【解决方案1】:

您应该确保使用GET 方法在路由中显示表单。使用验证时,如果验证失败,Laravel 会重定向(使用GET 方法)到显示表单的路由。因此,在这种情况下,当您有多个步骤表单时,您应该将数据放入会话并处理 GET 方法以用于使用验证的步骤。

【讨论】:

  • 我做了这样的事情 '$validator = Validator::make($request->all(), [ 'code' =>'required|numeric|size:4' ]); if ($validator->fails()) { Session::flash('error', $validator->messages()->first());返回重定向()->back()->withInput(); }' 但它给了我同样的错误。虽然我试图改变从 post 到 get 的路线,但它给了我同样的错误,并且认为 REQUEST_METHOD "POST" ,没有得到@Marcin Nabiałek
猜你喜欢
  • 2020-06-11
  • 2020-09-04
  • 1970-01-01
  • 2021-06-17
  • 2020-05-15
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
相关资源
最近更新 更多