O'Reilly logo
  • GIL EG thinks this is interesting:

Now, you can define this polymorphic relationship using the morphTo() and morphMany() methods.

  • The morphTo() method is used by the class that is related to all the other classes.
  • The morphMany() method is called by the owner classes.

So, let's edit our models like this:

  // file: app/Photo.php
  <?php namespace App;

  use Illuminate\Database\Eloquent\Model;

  class Photo ...


Cover of Learning Laravel's Eloquent


Polymorphic relationship, where a model is related to other several models depends on the record type is saved.