Skip to content
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

[8.x] Fix Eloquent Model 'loadMorph' and 'loadMorphCount' #34972

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

lBodia
Copy link
Contributor

@lBodia lBodia commented Oct 26, 2020

Currently, calling loadMorph or loadMorphCount throws an exception (get_class() expects parameter 1 to be object, null given) if requested polymorphic relation is null.

@taylorotwell
Copy link
Member

What do you mean if the requested polymorphic relation is null? Example of how to recreate?

@lBodia
Copy link
Contributor Author

lBodia commented Oct 26, 2020

  1. Create columns for polymorphic relation with $table->nullableMorphs('imageable') or just make imageable_id and imageable_type nullable
  2. Define imageable() relation inside Model
  3. Create an entry in DB leaving imageable_id and imageable_type empty
  4. Call $entry->loadMorph('imageable')

@taylorotwell taylorotwell merged commit 6defe37 into laravel:8.x Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants