访客和用户Laravel的注释表结构

I want release comments system for guest and site users. I need, when guest add comment, I need check email him. For it, when guest add comment, he can write "name", "email", "body" of comment. When he send comment, I need confirm email him, for it in table I have column email_token.

Now My comments table structure:

- id
- post_id
- user_id
- name
- email
- email_token
- email_verified_at
- body
- created_at
- updated_at

I have a question about structure of my table. How will be better? Do all columns for guest (name, email, email_token, email_verified_at) in comments table, or create separate table for guest comments? I need show all active comments in post model. If guest not confirmed email, then comment not active.

In post model I have this:

public function comments() {
    return $this->hasMany('App\Comment')->whereNotNull('email_verified_at')->orWhereNotNull('user_id'); //display only comments by user and guest (with confirmed email)
}

I suggest to have a separate table or you can use a users table which you may have used for registered user that way you can remove duplicate data.

In future, the guest user might become a site user as well. So better, you add one flag called "is_guest" or "type" in your user table.

I think your data organization is adapted to your use case (retrieve effectively active comments). The separation is not required because your table still have a reduced number of columns.

For the code part, you could have a Query Scope Comment::scopeOnlyActive() which would apply the whereNotNull/orWhereNotNull. That way, you could write it that way :

public function comments() {
    return $this->hasMany('App\Comment')->onlyActive();
}