I am working on a system in Laravel in which user can post, answer and vote on post or answer.
One way to do that is making separate vote tables for that but i wanted to do that with one table as votes.
I want that content_id in votes table should refer to two primary keys as posts.id and post-answers.id
If that solution is not possible then suggest an alternate solution for that. Thanks in advance.
I tried to make this migration but to no avail the table is created successfully but foreign key just pointing only one primary key.
public function up()
{
Schema::create('contentvotes',function(Blueprint $table){
$table->increments('id');
$table->enum('content_type',['post','post_answer']);
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->integer('content_id')->unsigned();
$table->foreign('content_id')->references('id')->on('posts');
$table->foreign('content_id')->references('id')->on('postanswers');
$table->boolean('status');
$table->timestamps();
});
}