samedi 15 octobre 2016

Reverse polymorphic relation in Laravel 5

Suppose we have following models: a Warrior, an Axe and a Sword

Is there a way to make the following behavior possible?

$warrior->weapon = $sword;
// ...

or

$warrior->weapon = $axe;
// ...

In other words, is it possible to treat separate models as if they had similar types with Eloquent?

P.S

Obviously, above is a simplified example of a problem serving the purpose of conveying the gist of it.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire