0
votes

I need do email verification for comments system. When guest create comment, he can write email, name, and body of comment. When user send comment, I need verify email him. And If he confirms email, then I need to publish comment. How can I do it with standard Laravel Email Verification? I have model Comment, and I have in tables comments columns: email, email_verified_at. Maybe I can implement Trait Email Verification for model Comment? I don't need to check whether user has verified his email address or not. If yes, then user should be able to post a comment. I need every comment verify email him. 1 comment = 1 verified email (even if it is repeated), how I can do it?

In model comment I tryied implement VerifyEmail:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;

class Comment extends Model implements MustVerifyEmail
{
    use Notifiable;

    // ...
}

But what I need do next? In docs only one middleware: ->middleware('verified') and this for user model, how I can send notification email activation for comment model and do middleware for comment model?

2

2 Answers

2
votes

You can simply make a custom verification. You can add a email_verified boolean column and set it false by default. Make a route and method which will change the comment's email_verified value to true from false. In comments displaying page, you only show the comments which's email_verified column is true. Now whenever a user make a comment, sent him a email containing the URL for that comment which will change the email_verified to true for that comment.

It's basic process and you can make it more efficient using separate table, token and laravel Observer.

1
votes

I would not use the email verification for another model.

Create an observer for the comment model then add a verified boolean to the migration table of the comment.

When the comment is created your observer will be able to trigger a notification to the guest.