Answer the question
In order to leave comments, you need to log in
Comments on anything. Is there a logic to the finished bike?
I make website services. For example, announcements, questions and answers, and more. Comments are needed everywhere.
I made my own for each section. Your own table. Your model and more. But then I decided to think and ask. It's not better to do this:
Create a single table and a single model. Since the rules of comments are the same everywhere. Just text and that's it.
In the table, make a field of type section id. That is, store all comments in one table, separating them by section id.
How do you think?
Answer the question
In order to leave comments, you need to log in
We create a table:
id (int), user_id (int), comment (text), commentable_type (string, index), commentable_id (int, index)
And the model below it:
class Comment extends Model
{
protected $table = 'comments';
public function commentable()
{
return $this->morphTo();
}
}
public function comments(){
return $this->morphMany('App\Comment', 'commentable');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question