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

Livewire throws error when passing EloquentCollection that does NOT contain objects #1980

Closed
christophrumpel opened this issue Nov 6, 2020 · 7 comments
Assignees

Comments

@christophrumpel
Copy link
Contributor

Description

If you pass to your Livewire component an EloquentCollection which does not hold objects, Livewire will throw an Exception like get_class() expects parameter 1 to be object, ...(other type) given.

In our case, we were receiving data from the DB and we transformed it.

$this->cart->items->mapWithKeys(function($item){
    return [$item->id => $item->pivot->quantity];
})

We could easily quick-dirty-fix it by transforming it into a default collection.

collect($this->cart->items->mapWithKeys(function($item){
    return [$item->id => $item->pivot->quantity];
})->toArray());

I assume Livewire is handling EloquentCollections differently which causes this issue.

Exact steps to reproduce

I have created a LaravelPlayground setup to demo the issue in a simple way: https://laravelplayground.com/#/snippets/f8ac92e0-6abc-4452-9521-35795a225723

Stripped-down, copy-pastable code snippets

See LaravelPlayground example.

Context

  • Livewire version: 2.3.0
  • Laravel version: 8.11.2
  • Alpine version: 2.7.0
  • Browser: Brave
@christophrumpel
Copy link
Contributor Author

@nuernbergerA pointed out that it seems this is more a Laravel issue than a Livewire issue since serialization on the Laravel side is leading to this error.

@nuernbergerA
Copy link
Contributor

Will open a PR soon

@nuernbergerA nuernbergerA self-assigned this Nov 6, 2020
@nuernbergerA
Copy link
Contributor

laravel/framework#35129

@nuernbergerA
Copy link
Contributor

Should be fixed with the next Laravel release.

@squishythejellyfish
Copy link
Collaborator

👋 Oh Hi! I'm Squishy, the friendly jellyfish that manages Livewire issues.

I see this issue has been closed.

Here in the Livewire repo, we have an "issues can be closed guilt-free and without explanation" policy.

If for ANY reason you think this issue hasn't been resolved, PLEASE feel empowered to re-open it.

Re-opening actually helps us track which issues are a priority.

Reply "REOPEN" to this comment and we'll happily re-open it for you!

(More info on this philosophy here: https://twitter.com/calebporzio/status/1321864801295978497)

@prazeev
Copy link

prazeev commented Apr 26, 2022

This issue still exists and not fixed yet

@Ryuuji159
Copy link

REOPEN

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

No branches or pull requests

5 participants