5 months ago

Adding data in pivot table with array structure in form

Posted 5 months ago by AbdulBazith

i have a small doubt. this doubt is about online quiz application

i have the below tables

Table: classDetails

id  class_name
1   5th std
2   6th std
3   7th std
Table: SubjectDetails

id  sub_name
1   english
2   maths
3   physics
Table: Chapter table

id  subject_id      ChapterName
1   1               	Matrices
2   1              	 Integration
3   1               	Differentiation
4   3              	 Electrostatics
5   3              	 Tranformation
6   3              	 Electricity
Next Topic table

id  chapter_id          Topic_id
1   1              Inverse of a Non-Singular
2   1             Elementary Transformations of a Matrix
3   1           Solving System of Linear Equations
4   4           Role of electrostatic
5   4           Electric flux
6   4           Polaraisation

Based on suggestion : https://laracasts.com/discuss/channels/laravel/mapping-class-and-subject-and-chapters-into-many-to-many-relationship-laravel

i planned to have relation ship like this

classes ( id, name ) //slug or others if you want
subjects (id, name ) // slug or others if you want
chapters(id, name, subject_id)	// this belongs to a subject so it's a "child"
topics (id, name, chapter_id) // topic is child of chapter
class_topic (id, class_id, topic_id) // this is the pivot table because each class studies a topic...

Now i have added class, subject, chapter.

iam going to add topic, so i have a form like this

Add Topic form
class_id:	(dropdown)	subject_id:(dropdown)    Chapter_id:(dropdown)

Topic1:   (textbox)
Topic2:	(textbox)
TopicN: (textbox)

Here the topic name: topic[] array structure. how to insert this is pivot table mypivot table is

id	class_id		 topic_id

whether first i need to enter the topic and then i need to map the class and topic in separate form, else while inserting the topic itself i can insert that in pivot table?

another doubt i need to have a question table is these fields right

topic_id  (fk)
explanation_image (optional)
explanation_pdf (optional)

with the topic id i can find that which class, which subject, which chapter which topic this question belongs to? is this right? else i need to give some other as foreign key.

Kindly some one suggest please

Please sign in or create an account to participate in this conversation.