superfantastic's avatar

What is the best way to structure these models?

New Laravel convert here, so please forgive me if my question format isn't great!

I have a model called Grant, and each Grant's data storage/format requirements can be set by what I've called a GrantFormat. Most Grants in the system will be of a standard GrantFormat, but in the future additional GrantFormats will be introduced and these will alter the data structure for that Grant (save for a few common fields like the grant's name, ID number, etc). The GrantFormat also determines how data in another part of the system will be recorded, as different GrantFormats will have different requirements as to what data needs to be collected.

My thinking was to have each Grant own one GrantFormat and then specify a 3rd table where the data for that Grant is recorded in the appropriate format. This however doesn't feel quite right to me, and I think due to my lack of experience I'm missing a more Eloquent way of structuring this?

The best analogy I can think of to another similar setup would perhaps be Posts having different PostTypes? Perhaps the PostTypes could include Blog, Image, Video, Audio, etc and therefore the type of data you're recording per type will be different, but they're all still Posts?

Many thanks for your help!

0 likes
2 replies
superfantastic's avatar

Yeah, that did cross my mind also, in the end though having spoken to a colleague, I've gone down a route of codifying each 'format' as it's own model. This better represents how the data itself is being stored and doesn't rely on any intermediate tables to connect the Grant and it's format data.

Thank you for the link though, there are so many discussions going on in my head on how to best represent data using Eloquent so I'm sure that'll be a huge help!

Please or to participate in this conversation.