2

Ok so i have a model named SiteEmail. Basically i have a model named Site and it can have multiple emails associated with it, which has to be verified by sending an email. I want to use the laravel email verification that ships with laravel which i have used on the user model. I have implemented the MustVerifyEmail interface on the SiteEmail model and it is using the Notifiable trait. The emails are being sent fine, but on clicking on the verify button, it says invalid signature.

class SiteEmail extends Model implements MustVerifyEmail
{
    use Notifiable;
    protected $fillable = ['site_id', 'user_id', 'email', 'email_verified_at'];

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

    /**
     * Mark the given user's email as verified.
     *
     * @return bool
     */
    public function markEmailAsVerified()
    {
        $this->update([
            'email_verified_at' => now(),
        ]);
    }

    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }

    /**
     * Get the email address that should be used for verification.
     *
     * @return string
     */
    public function getEmailForVerification()
    {
        return $this->email;
    }
}

How do i approach email verification on such models? It works fine on the User model, but i don't think this is the correct way to verify custom models. Any help is appreciated! Thanks!

PS: I think this might be happening because the signature generated is being tested against the user's email?

Ashok
  • 369
  • 5
  • 16
  • Pull the contract it should work see; https://laravel.com/docs/8.x/contracts MustVerifyEmail is pulled by Authenticable class. Similar ;https://laracasts.com/discuss/channels/laravel/mustverifyemail-it-is-not-a-trait – Danys Chalifour Apr 01 '21 at 17:06
  • @DanysChalifour Nop still says invalid signature – Ashok Apr 02 '21 at 02:21
  • 1. Is APP_URL the same you have domain or location of root directory? Pl do set like that. 2. Is forceHTTP enabled? Pl disable 3. `php artisan config:cache` Hope these helps – Kaushik Thakkar Apr 03 '21 at 06:14
  • @KaushikThakkar yes it is – Ashok Apr 03 '21 at 09:21
  • Did it help or still stuck? – Kaushik Thakkar Apr 03 '21 at 11:17
  • @KaushikThakkar no actually i didnot use the trait or the contract, ended up making something of my own. I think the default verify controller checks the email against the user's email or something like that. So i ended up creating a different route to verify the url instead of the default verify route, and verified the url's signature on a custom controller. But i still dont fell like i completely understand why is it happening. – Ashok Apr 03 '21 at 13:48

0 Answers0