【问题标题】:Laravel will not route properly from formLaravel 无法从表单正确路由
【发布时间】:2019-07-13 07:59:45
【问题描述】:

在 URL 用户/密码/更改我有一个表单:

{!! Form::open(array('route' => 'password.recover')) !!}
    <div class="form-group">
        <label for="email">Email Address</label>
        <input type="email" class="form-control" name="email" id="email" value="{{ old('email') }}" />
    </div>
    <div class="form-group">
        <label for="password">New Password</label>
        <input type="password" class="form-control" name="password" id="password" />
    </div>
    <div class="form-group">
        <label for="password_confirmation">New Password (again)</label>
        <input type="password" class="form-control" name="password_confirmation" id="password_confirmation" />
    </div>
    <div class="form-group">
        <label for="password_confirmation">Verification Code (from text message)</label>
        <input type="text" class="form-control" name="verification_code" id="verification_code" />
    </div>
    <button type="submit" class="btn btn-primary btn-block">Reset Password</button>
{!! Form::close() !!}

该表单位于刀片views/auth/reset.blade.php

表单操作正在我的 routes.auth 文件中调用此路由:

Route::post('password/recover', 'Auth\AuthController@reset')
->name('password.recover');

问题是当我提交表单时出现MethodNotAllowedHTTPException 错误。如果我从错误页面点击返回,那么我的表单会加载我的表单验证错误(因为表单提交为空)。所以它在我的 AuthController 中点击了重置功能,但它有某种路由错误。如果我尝试提交空表单,它应该只重新加载包含错误的页面,而不是给出异常错误。

我在这里遗漏了一些非常明显的东西吗?

【问题讨论】:

  • Form::open(array('route' =&gt; 'password.recover', 'method'=&gt;'post'))

标签: php laravel


【解决方案1】:
Form::open(array('route' => 'password.recover', 'method'=>'post'))

您没有传递正确的 http 方法。该路线期待发布,但您使用的是默认设置。

【讨论】:

    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2021-07-18
    • 1970-01-01
    • 2018-01-17
    • 2017-10-15
    相关资源
    最近更新 更多