Dronax
261
4
Laravel

Comment table structure for guest and user Laravel

Posted 4 months ago by Dronax

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)
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.