Polymorphic Eloquent relationships with namespaces

Since Laravel 4.1, inside your model (in this case Company and People) you can set the protected property $morphClass to whatever you want.

<?php namespace Lion;

class Company extends \Eloquent { 

    protected $morphClass="Company";
}

Now in your table you can store the type without the namespace:

 |  id  |  realatable_type  |  relatable_id
 |  2   |  Company          |  13

Leave a Comment