Home > front end >  Customize email_verified_at column in laravel
Customize email_verified_at column in laravel

Time:02-16

I am currently working on a laravel project that needs to send a verification email. I successfully send an email but when I try to verify the email by clicking "Verify email address" button in the email it shows me the error unknown column "email_verified_at". I don't have rights to add or edit fields in the database. I am just wondering where can I change this field to something else? like instead of email_verified_at I'll use emailVerifiedAt

CodePudding user response:

If you have changed the email_verified_at column name to something else you can try this

By default laravel User model extends Illuminate\Foundation\Auth\User and this class is using a trit named Illuminate\Auth\MustVerifyEmail which contains all the logic for verifying email address. So you can override the methods of trait inside User Model

Inside the User.php model

/**
     * Determine if the user has verified their email address.
     *
     * @return bool
     */
    public function hasVerifiedEmail()
    {
        return ! is_null($this->emailVerifiedAt);
    }

    /**
     * Mark the given user's email as verified.
     *
     * @return bool
     */
    public function markEmailAsVerified()
    {
        return $this->forceFill([
            'emailVerifiedAt' => $this->freshTimestamp(),
        ])->save();
    }
  • Related