0
votes

What it has to do :

I am trying to create my own password reset from scratch using Laravel. I have a password_resets table which has 3 columns : email, token, created_at . I am getting the user to enter his email to which the password reset mail is to be sent. After the user enters the email, the function "send" in my ResetController checks whether the the email id exists in the table of users. If it exists, then a token is created and then the email and token is stored in the password_resets table. Then a recovery mail is sent to the email address with a link to reset the password.

Where it goes wrong

When I try to save the data to my password_resets table, laravel throws this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into password_resets (updated_at, created_at) values (2018-07-07 13:11:15, 2018-07-07 13:11:15))

But there is no updated_at column in my password_resets table

Below is the Structure of the password_resets table :

email varchar(191) - token varchar(191) - created_at timestamp

My ResetController file :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;
use App\PasswordReset;

class ResetController extends Controller
{
  public function show() 
  {
    return view('reset.index');
  }

  public function send() 
  {
        $email = request('resetemail');

        if(User::get()->where('email','[email protected]')!=null)
        {
            $token = bin2hex(openssl_random_pseudo_bytes(16));

            PasswordReset::create([
            'email'=> $email,
            'token'=> $token
            ]);
        }
   }  
 }
1

1 Answers

1
votes

Per the Eloquent Model Conventions:

By default, Eloquent expects created_at and updated_at columns to exist on your tables. If you do not wish to have these columns automatically managed by Eloquent, set the $timestamps property on your model to false:

So, you could solve your problem by adding public $timestamps = false; to your model.

Alternatively you could add the timestamp fields to your table by adding $table->timestamps(); to your migration and rolling it out. See the available column types creating columns in the Laravel documentation.