I activated the email confirmation in my Laravel project, when i receive the email and click the button the site return me an exception.
The code line interested is in the User Class:
<?php
namespace AppModels;
use CarbonCarbon;
use DateTimeInterface;
use Hash;
use IlluminateAuthNotificationsResetPassword;
use IlluminateContractsAuthMustVerifyEmail;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentSoftDeletes;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
class User extends Authenticatable implements MustVerifyEmail
{
use SoftDeletes, Notifiable, HasFactory;
public $table = 'users';
protected $hidden = [
'remember_token',
'password',
];
protected $dates = [
'email_verified_at',
'created_at',
'updated_at',
'deleted_at',
];
protected $fillable = [
'name',
'email',
'email_verified_at',
'password',
'remember_token',
'created_at',
'updated_at',
'deleted_at',
'firstname',
'lastname',
'address',
'postcode',
'place',
'company',
'phone',
'mobile',
];
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
public function getIsAdminAttribute()
{
return $this->roles()->where('id', 1)->exists();
}
public function getEmailVerifiedAtAttribute($value)
{
return $value ? Carbon::createFromFormat('Y-m-d H:i:s', $value)->format(config('panel.date_format') . ' ' . config('panel.time_format')) : null;
}
public function setEmailVerifiedAtAttribute($value)
{
$this->attributes['email_verified_at'] = $value ? Carbon::createFromFormat(config('panel.date_format') . ' ' . config('panel.time_format'), $value)->format('Y-m-d H:i:s') : null;
}
public function setPasswordAttribute($input)
{
if ($input) {
$this->attributes['password'] = app('hash')->needsRehash($input) ? Hash::make($input) : $input;
}
}
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}
public function roles()
{
return $this->belongsToMany(Role::class);
}
}
The problem is in the line 68:
public function setEmailVerifiedAtAttribute($value)
{
$this->attributes['email_verified_at'] = $value ? Carbon::createFromFormat(config('panel.date_format') . ' ' . config('panel.time_format'), $value)->format('Y-m-d H:i:s') : null;
}
I try to change the timezone in the app.php but the problem still remain.
In the DB the user is registred, and can access to the website, but the field “email_verified_at” is null.