I wrote a login system myself and for authentication I us auth
and User
model.
Now I want to wrote Reset Password,
I found PasswordBroker
so I wrote a method in my controller:
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');
});
}
But when I trying to reset my password I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `users` where `0` = [email protected] limit 1)
What should I do?
UPDATE :
my users
migration:
<?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');
}
}
I found the solution,
In sendResetLink
we should pass email
as key
in first parameter,
so my code should change to this:
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');
});
}