Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asdasdsa's avatar

Am I doing this to advance?

Hi! Wrote a long and good post, but when to post it. I got a "Whoops something went wrong", and when clicked "previous" in the browser, my post was long gone :( So let me try to recreate my post.

Im trying to create a quiz app. And for this i was thinking on going with a threaded design. With subjects, containing topics, and then the actual questions. So for example. Choosing a subject, "Cars". Then choosing a topic "Engine", then only questions about the engine. Another example. Subject "Cars", topic "Brands". Questions about car brands!

The structure i was planning is this:

Subject

Subject_id (increments)
Subject (string)
Description (text)
Image_url (string)(nullable)
softDeletes
timestamps

Topic

Topic_id (increment)
Topic (string)
Description (text)
Image_url (string)(nullable)
Subject_id
softDeletes
timestamps

Content

Content_id (increment)
Image_url (string)(nullable)
Is_Info (boolean)
Info_text (text)
Question_text (text)
Question_explaination (text)
Question_Source (text)
Topic_id
softDeletes
timestamps

And for even more simplicity, i store the questions choices separately.

Choice_id
Content
Correct (boolean)
Content_id
timestamps

So what do you guys think? How about foreign key constraints? Or other things to think about?

0 likes
7 replies
TheFriendlyHacker's avatar

Just to make sure I am on the same page, you want your quiz to be structured something like this:

Subject->topic->questions

For example, Subject: Animals Topic: Reptiles Only show questions about Reptile animals?

1 like
martinbean's avatar

@asda Could you not just have a hierarchical category? What happens if you want a topic that’s more specific? Are you going to create another table and model for sub-topics?

With a hierarchical model, you can get as specific as you like.

Schema::create('categories', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('parent_id')->nullable();
    $table->string('name');
    $table->timestamps();
    $table->foreign('parent_id')->references('id')->on('categories');
});
asdasdsa's avatar

@martinbean As for now, I'm not planning on sub-topics, but maybe thats good for future. How would that look like then?

martinbean's avatar

@asda Yeah. You might have a category called “Cars” with an ID of 1. Then if you wanted an “Engines” sub-category, you would set that record’s parent_id value to 1

Please or to participate in this conversation.