osebo-gotokuo's avatar

How to link users model to multiple models

Hi, i have an old sql file from the old corydating script that i want to port to laravel the problem is the sql file have many tables and each table have it's columns. E.g table = Eye color column = black ............. .......... Table = Gender clumn = male ......... ...... And many more, more than 10 so i want to create a model for every table. But the problem is how do link all the model to the user model? Your help will be very much appreciated.

0 likes
5 replies
tykus's avatar

How are the relations between the tables defined already; is there a foreign key?

2 likes
osebo-gotokuo's avatar

@tykus Thanks a lot for your response. The design is like this: Gender table has it's columns Hair color table with it's columns like the rest Then the profile table gets filled with all the related/corresponding columns from the other tables . Like this: Table = Profile Column Smallint(genderid) smallint(haircolorid) ................. ................. The file is very old as the script only supports php 5.6

tykus's avatar

@osebo-gotokuo so you have individual tables for profile attributes? And the profile table connects particular attributes, e.g. male, black hair etc. .with the User?

1 like
jlrdw's avatar

Also I suggest looking over the eloquent relations in detail to help you decide on the relations to use:

You could have have multi one to many relations, but that's just one way.

I have used two child tables when I had to have picks and drops for trucks.

Basically:

Load
----picks
----drops

https://laravel.com/docs/10.x/eloquent-relationships

Also the free laravel training might point you in the right direction.

Edit:

A while back martinbean and tray2 gave some answers concerning product variations. Like shirt color, size, etc. If you search for those post you may be able to adapt some of the logic to your application.

2 likes

Please or to participate in this conversation.