vendredi 30 octobre 2015

Laravel 5.1 eloquent relations

I was implementing a quiz system using Laravel 5.1

I was facing some problems with inserting and updation of data in questions table

MySQL Schema

Subjects  (Table 1)
________________
Subject_ID (Primary Key) auto_increment,
Subject_Name


Questions (Table 2)
________________
Question_ID (Primary Key) auto_increment,
Question,
Options_1,
Options_2,
Options_3,
Options_4,
Answer,
Subject_Id (Foreign Key refers to Primary Key of Subjects Table [Table 1])

While inserting question in the questions table, I was unable to get the Subject_Id from Subjects table

I was implementing the following query using Laravel

insert into questions values("", "Question", "Option 1", "Option 2", "Option 3", "Option 4", "Answer", "select subject_id from subjects where subject_name = $subject_name");

$subject_name is the variable that fetches the subject name from the user interface



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire