我自己编写了一个登录系统并进行身份验证我们是auth
和User
模型。
现在我想写一个重置密码,
我找到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');
}
}
答案 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');
});
}