-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional polymorphic relation results in fatal error #1450
Comments
+1. Got the same thing, only I'm using |
I'm glad to know I'm not the only one facing this issue! |
Yea, optimally this would return an empty collection. |
I'm confused. What is happening? imagable should just return |
Yes. In case of |
Well the problem is really with |
Yeah, sorry my bad |
I'm having the same issue here.. Any solutions? |
This is just a fundamental part of morphTo(). You can't create the morphTo object without already having a direct mapping to the target model. You can create a setter that does something like:
Which then does something like..
|
At the moment if you use polymorphic relations there always has to be a relation, otherwise an error occurs
PHP Fatal error: Class name must be a valid object or a string
. Thats clear since the implementation of themorphTo
method looks up for a class of type xy. If no such is provided it results in an error.For "normal" relations if two models are allowed to be in a relation but they aren't thats fine. The same behavior would be nice for polymorphic relations.
Example (from docs):
If a Photo would be not in a relationship with a Staff model and just "lives on his own", that should be possible two and not result in an error.
The text was updated successfully, but these errors were encountered: