缺少自定义密码重置的Route所需的参数

时间:2018-03-16 13:14:52

标签: laravel routes

我试图添加新类型的用户" Client"进入现有项目。

它已经有了#34; Admin"用户,没有电子邮件密码重置功能。

我复制并修改了本机Laravel开箱即用的Auth控制器,刀片表单和模型,现在我可以登录并注销为客户端(后卫:客户端)。

我的问题在于密码重置功能 "忘记了密码?"按钮重定向到右侧URL(http://127.0.0.1:8000/client/password/reset) "发送密码重置链接"按钮生成带有链接(http://127.0.0.1:8000/client/password/reset/a7558b0f294af7cdaeafd73617f664e1d76ed27d567d648e8b468eb9edcc9c2d

的电子邮件

但是当推送链接时我得到以下错误:

  

缺少[Route:client.password.reset]所需的参数[URI:   客户机/口令/复位/ {令牌}]。 (视图:   C:\ wamp64 \ WWW \ testkz \资源\视图\索引\客户\ reset.blade.php)

其中reset.blade.php是resources \ views \ auth \ passwords \ reset.blade.php

的副本

我的路线

Route::post('/password/email','Client\ClientForgotPasswordController@sendResetLinkEmail')->name('client.password.email');
Route::get('/password/reset','Client\ClientForgotPasswordController@showLinkRequestForm')->name('client.password.request');
Route::post('/password/reset','Client\ClientResetPasswordController@reset');
Route::get('/password/reset/{token}','Client\ClientResetPasswordController@showResetForm')->name('client.password.reset');

ClientResetPasswordController

<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Password;
use Auth;

class ClientResetPasswordController extends Controller
{
  use ResetsPasswords;
  protected $redirectTo = '/client';
  public function __construct()
  {
    $this->middleware('guest:client');
  }

  protected function guard()
  {
    return Auth::guard('client');
  }

  protected function broker()
  {
    return Password::broker('clients');
  }

  public function showResetForm(Request $request, $token = null)
  {
    return view('index.client.reset')->with(
      ['token' => $token, 'email' => $request->email]
    );
  }
}

刀片

@extends('index.layout.layout')

@section('content')
  <div class="container">
      <div class="row">
          <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Reset Client Password</div>

                <div class="panel-body">
                    @if (session('status'))
                        <div class="alert alert-success">
                            {{ session('status') }}
                        </div>
                    @endif

                    <form class="form-horizontal" role="form" method="POST" action="{{ route('client.password.reset') }}">
                        {{ csrf_field() }}

                        <input type="hidden" name="token" value="{{ $token }}">

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ $email or old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                            <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>

                                @if ($errors->has('password_confirmation'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password_confirmation') }}</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">
                                    Reset Password
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
          </div>
      </div>
  </div>

@endsection

2 个答案:

答案 0 :(得分:0)

确保表单方法ID POST

 <form class="form-horizontal" method="POST" action="{{ route('password.request') }}">
   {{ csrf_field() }}
   <input type="hidden" name="token" value="{{ $token }}">
</form>

答案 1 :(得分:0)

我将项目从Laravel 5.3升级到5.5,但使用了旧版本的reset.blade.php