-1

I have a "Files" table (id, Name, Path, Owner). I want to link the Owner column to multiple tables (students, supervisors ...). For example the owner of a file could be a student, supervisor or Evaluating committee. What is the efficient solution to this problem since I can not reference a foreign key to multiple tables?

Armali
  • 18,255
  • 14
  • 57
  • 171
  • 1
    You could have separate connecting tables for each possible owner, or restructure you database so that student, supervisor, and committee tables are all in one "users" table (and differentiated by a user type field); with optional student_details, staff_details, and/or committee_details tables for information unique to the different types. – Uueerdo Nov 20 '18 at 20:20
  • This might be a good start: https://stackoverflow.com/questions/7844460/foreign-key-to-multiple-tables – Adam Rodriguez Nov 20 '18 at 21:41

1 Answers1

0

You are best using a polymorphic relationship.

https://laravel.com/docs/5.7/eloquent-relationships#polymorphic-relations

Alternatively you could have a users table and have different roles for users using something like https://github.com/spatie/laravel-permission

Josh
  • 1,316
  • 10
  • 26