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

gcbenlloch's avatar

Extend model with multiple tables

I have what I consider is a strange case and I don't know how to implement it correctly in Lumen.

I'm working on some apps for a school where some models are use accross multiple APIs. In my case I have a user model wich is morphed in students, workers and parents.

I have two APIs, one for book selling and another for the school canteen. Currently both APIs have their own database with their own user model but I would like to have one database to manage all common models and extends each model on the API specific database.

Would it be possible to have a common database with the shared attributes of each model and in each API database extend the model with data specific to that API? I searched on the forum but I didn't find anything relatet to that.

0 likes
9 replies
vincent15000's avatar

I'm not sure to understand.

Do you want to create a kind of copy of some datas from the API in order to use them locally ?

1 like
gcbenlloch's avatar

@vincent15000 As all APIs share some models, like users, students and parents I would like to have a common database with the common attributes of that models, like email, cou, etc and in each specific API have the same model with the data from the common database with some API specific attributes.

For example. The student model have the class in all APIs, but in the books selling API have a list of buyed books and in the library API a list of borrowed books. So I would like to have a common database with the sutend name and class, a books selling database with the student id and the buyed books and the library database with the student id and the borrowed books.

I really dont know if it is possible or if there is any better way of sharing some model attributtes across APIs

1 like
vincent15000's avatar

@gcbenlloch Ok ... you have for example a Student model and you want to have in the students tables some fields where the datas come from different APIs. Have I understood ?

gcbenlloch's avatar

@vincent15000 Yes, but I was just wondering if the data for the same model could be in different tables to avoid having a lot of attributes from different APIs in just one table.

gcbenlloch's avatar

@sr57 I know, that was one option but in that case the user model would need to have the attributes needed in all APIs. So I was wondering if there is any way of one model having attributes in two differente tables, one common to all APIs and another API specific

1 like
sr57's avatar

@gcbenlloch

don't understand, your api data can be generated from different models (and from different db in your case)

1 like
vincent15000's avatar

@gcbenlloch Ok that's clearer for me now ... why don't you simply create different tables and you fill them with the datas coming from the differents APIs. That's not a problem because you will work with the same database, but with different APIs. And working with different APIs is not a problem.

But you will perhaps have to check the integrity of your datas.

gcbenlloch's avatar

@vincent15000 That would be a great option, I just thought if it was possible to have multiple databases it would avoid having in the student table all the fields from all the APIs

Please or to participate in this conversation.