I have 3 tables:
1) CourseA
2) CourseB
3) Orders
Here is the structure of CourseA table:
id | course_title
1 | Maths
3 | Physics
Here is the structure of CourseB table:
id | course_title
2 | Biology
6 | Physcology
Here is the structure of Orders table:
id | course_id | course_type
1 | 1 | 1
2 | 2 | 2
(Note: course_type == 1 means the record belongs to CourseA table, & course_type == 2 means the record belongs to CourseB table).
Now here in Orders table, course_id is a foreign key depending on 2 different tables.
How can I use Laravel Migration for this type of scenario?
I tired something like this but its not working:
Schema::table('orders', function($table)
{
$table->foreign('course_type')->references('id')->on('courseA');
$table->foreign('course_type')->references('id')->on('courseB');
});
Any idea what is wrong here?