【发布时间】:2020-06-25 10:41:52
【问题描述】:
我将 laravel 5.2.4 更新到 5.6。 在修复一些错误时,我在重置密码时遇到错误 - “需要令牌字段。”
我在表单中使用参数 - @csrf
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}">
@csrf
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-envelope"></i>Send Password Reset Link
</button>
</div>
</div>
</form>
在路线中
Route::get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
Route::post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
Route::post('password/reset', 'Auth\PasswordController@reset');
密码控制器:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
/**
* @property string linkRequestView
* @property string resetView
*/
class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Create a new password controller instance.
*
* @param Request $request
*/
public function __construct(Request $request)
{
$this->middleware('guest');
$this->linkRequestView = 'auth.passwords.email';
$this->resetView = 'auth.passwords.reset';
if (strpos($request->path(), 'ex') === 0) {
$this->linkRequestView = 'ex.auth.passwords.email';
$this->resetView = 'ex.auth.passwords.reset';
}
}
}
我必须改变什么来解决这个问题? 当我在页面上看到 html 代码时 - 令牌字段存在“_token”但当我提交时 - 需要令牌。
【问题讨论】: