multiple foreign key indicating one primary key and getting values from table
guys iam working with a project quiz examination.
before writing the exam assessment must be created.
i have a for to create assessment. in that
assessment name:
for which class: class_id (referencing class table)
which subject: subject_id (referencing subject table)
which chapter: chapter_id (referencing chapter table) -> this is the matter. i have multiple select in form. more than one chapter can be selected
how this is possible
for single select i have table structure like this
id assmnt_name class_id subject_id chapter_id
1 Asmnt1 1 1 1
for this i get get the eloquent from DB easyily. just passing where condition of class_id, subject_id, chapter_id
but my client expecting multiple chapter selection. how can i make my table structure??
and after that how can i get it from DB say for example if 3 chapters are selected means so getting question from question table where chpater_id=1,2,3.
how this is possible?
So you are talking about a many to many relation then you need to use a pivot table that contains the subject_id and the assessment_id.
https://laravel.com/docs/7.x/eloquent-relationships#many-to-many
Please or to participate in this conversation.