Reputation: 6639
I have the following model
class PasswordResets extends Model
{
protected $table = 'password_resets';
protected $fillable = [
'token', 'email'
];
public function setUpdatedAt($value){
;
}//tried this but fails to work
}
I have tried using the function setUpdatedAt
but still fails
The way I am using this model is
$passwordreset = PasswordResets::where('email', $user->email)->first();
if(!$passwordreset){
//insert user to password reset
$passwordreset = new PasswordResets();
$passwordreset->email = $user->email;
}
$passwordreset->token = sha1(time());
if($passwordreset->save()){
//send emails to user
}
Basically am trying to find if a user exist in a password reset table other wise add a new one then send email.
Every time I try, I am getting an error
Column not found: 1054 Unknown column 'updated_at'
Which is true since my table only contains the column created_at
.
How do I stop the updated_at
from being filled up?
Upvotes: 0
Views: 826
Reputation: 25221
Laravel automatically tries to set the created_at
and updated_at
fields every time you create or edit a model. If you don't want to use that functionality, add this to your model:
public $timestamps = false;
You will then have to set your created_at
column manually.
To automate the created_at
column, just use a default in your migration:
$table->timestamp('created_at')->default('CURRENT_TIMESTAMP');
Upvotes: 2