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

janisozolins's avatar

Laravel Eloquent Models with embedded MongoDB documents

Hi there,

I am struggling to understand how MongoDB database structure can be used within Laravel.

I have one collection with documents of "patients", and each document embeds sub-documents on multiple levels in arrays like "diagnosis", "subscriptions" and other sub-documents.

In this case, am I supposed to create different eloquent models for each sub-document group? Or just use everything with my default "Patient" model? Which is the most optimal method that would help me to look up associated prescriptions, diagnosis and other patient-related information for every patient?

an example of how my database structure will look like:

{
   _id: "joe",
   name: "Joe"
   diagnosis: [
                {
                  name: "asthma",
              prescriptions: [
            {
                name: "presc-1"
            },
            {
                name: "presc-2"
            },
            {
                name: "presc-3"
            }]
                },
                {
                  name: "back pain",
              prescriptions: [
            {
                name: "presc-1"
            },
            {
                name: "presc-2"
            },
            {
                name: "presc-3"
            }]
                }]
 }
0 likes
1 reply
rvkvino's avatar

Did you find any solutions for this, now I'm standing in same problem. If you have a solutions means please share

Please or to participate in this conversation.