It is necessary to design a database on Laravel where there are doctors and specialties , specialties are automatically --seed thanks to --seed ,

Help design relationships between doctor tables , specialties

if one doctor corresponds to only one specialty , but many doctors may have the same specialty .

If you can write in detail what is the relationship between the tables here and give a link to the Laravel documentation .

  • What's the big deal? There is a table of specializations in which id / profession name / etc. is unique. in the table of doctors, each doctor has a field of specialization, where there is a unique parameter from the table of specializations - Vladimir Afanasyev

1 answer 1

First option:

 doctor(id, name, description) specialities (id, title, description) set_specialities(id, id_specialities, id_doctor) 

The second option:

 doctor(id, id_specialities, name, description) specialities (id, title, description) 

How to continue to work with links here .

  • The second option is what you need. But to link tables, do I need to specify foreign_key in migration create_doctors_table or is this automatically done by the belongsTo method - a_mine
  • I always create keys in the table, so add a key to the migration. The first variant will, in the future, allow doctors to assign several special - Alexander Pshenichny
  • one
    I forgot about to write belongsTo)) it does not create keys, but works with them to communicate, there is still a moment if the application is designed for a large load, add the select method to the relationship, and call only the required fields from the tables, this will reduce the load - Alexander Pshenichny