Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

PhillSparks solved it in chat:

$this->morphOne('App/User', 'userable');
Last updated 2 years ago.
0

This is an old post, but just a note for anyone else who found this from a Google search of morphOne() (morphOne() isn't documented in the Laravel docs, so there is scarce information about it)... An important thing to be aware of is that morphOne()'s save() method currently doesn't check to make sure there isn't already an existing associated child object.

So if you call morphOne()'s save() repeatedly with different child objects, it will associate multiple objects with the parent, even though there's only supposed to be one (so in the terminology of the above example, you could end up with multiple users associated with a Person object).

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Almis90 almis90 Joined 25 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.