Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andreza.vieira's avatar

Multiple table inheritance in Laravel 5.1

Hi, I've read some comments about how to implement multiple table inheritance in Laravel, but I'm confused. In this thread (http://stackoverflow.com/questions/33462292/table-inheritance-in-laravel/38616585), I noted that a table inheritance was implemented. However, Laravel 5.1 documentation explains about "Polymorphic Relations" (https://laravel.com/docs/5.1/eloquent-relationships#polymorphic-relations).

This is my scenario: A "Person" can be a "Student", "Teacher" and/or "Candidate". The same person can be Student and Teacher at the same time, for example. This is a way to implement the models I think (I do not know if it is correct):

class Person extends Model {
        public function teacher(){
                  return $this->hasOne(Teacher::class);
  }
         public function student(){
                 return $this->hasOne(Student::class);
         }
          public function candidate(){
               return $this->hasOne(Candidate::class);
} 
}

class Student extends Person {
    public function person(){
        return $this->belongsTo(Person::class);
    }
}

class Teacher extends Person {
    public function person(){
        return $this->belongsTo(Person::class);
    }
}

class Candidate extends Person {
    public function person(){
        return $this->belongsTo(Person::class);
    }
}

In the database, I would create the tables:

  • Person (id, name, phone)
  • Student (person_id, etc)
  • Teacher (person_id, etc)
  • Candidate (person_id, etc)

This way, I do not use Polymorphic Relations as Laravel 5.1 explains. Any suggestions about the best way to accomplish this?

Thank you very much.

0 likes
0 replies

Please or to participate in this conversation.