I'm designing a database table called answers. The fields would be source_type and source_id, etc. The source_type is "question" or "comment", which are tables. Now the problem is I want source_id in answers table to reference either id in questions or id in comments depending on the value of the source_type field.
So in normal situation it would be either this:
$table->foreign('source_id')->references('id')->on('questions');
or this
$table->foreign('source_id')->references('id')->on('comments');
However how can I'm not sure how to add restriction in either table?