Having the following tables. What would be the best or conventional way to add relationships to these tables with eloquent?
I know that a Many to Many relationship will need a pivot table. The thing I'm not seeing samples of online is how to do a relationship from one table to multiple tables. In this case being the profiles table to sizes and breeds tables.
dogs
- id
- name
- profile_id
profiles
- id
- dog_id
- size_id
- breed_id
sizes
- id
- type
breeds
- id
- name
In the end I'd like to be able to query something like this:
Dogs that are sizes in(x-small, small, medium) and breeds in(chihuahua, maltese).
I don't want to confuse myself or others by posting what I'm guessing for my eloquent code as I'm not even close.
I think you need to create a database structure like below:
dogs
- id
- name
profiles
- id
- size_id
- breed_id
dog_profile
- dog_id
- profile_id
sizes
- id
- type
breeds
- id
- name
Then, create a model for each table and insert relationships such as described in laravel's documentation. You will need hasMany-belogsTo and belogsToMany-belogsToMany relationships.