Model inheritance

Posted 2 months ago by toniiiii

Hey everybody, let's say i have a model named Public transport. Now i want to have additional inherited models like bus, train or maybe plane.

My idea was my model public transport has a TYPE attribute which can be 'bus' or 'train' and a TYPE_ID. than depending on what type it is it should fetch the entry from the correct table.

For Example:

PublicTransport: 'bus', 1 should return with PublicTransport->type() an entry with id 1 from the bus table.

PublicTransport: 'train', 5 should return with PublicTransport->type() an entry with id 5 from the train table

i hope you understand what i mean. i don't really know how to solve this with laravel... in the future also new types should be added. maybe my approach is totally wrong.

please help me

Please sign in or create an account to participate in this conversation.