如何为laravel手动编写forgetpassword

时间:2016-10-16 09:49:53

标签: php laravel laravel-5.3

我自己编写了一个登录系统并进行身份验证我们是authUser模型。

现在我想写一个重置密码,

我找到PasswordBroker所以我在我的控制器中写了一个方法:

public function forgetPassword(Request $request, PasswordBroker $password) {
        if (empty($request->session()->get('email'))) {
            return redirect()->route('login');
        }

        $response = $password->sendResetLink([$request->session()->get('email')], function($message)
        {
            $message->subject('Password Reset');
        });

    }

但是当我尝试重置密码时,我收到了这个错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `users` where `0` = email@domain.com limit 1)

我该怎么办?

更新:

我的users迁移:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,

sendResetLink中,我们应将email作为key传递给第一个参数,

所以我的代码应该改为:

public function forgetPassword(Request $request, PasswordBroker $password) {
        if (empty($request->session()->get('email'))) {
            return redirect()->route('login');
        }

        $response = $password->sendResetLink(['email' => $request->session()->get('email')], function($message)
        {
            $message->subject('Password Reset');
        });

    }