I am trying to use groupBy on Eloquent Collection but livewire giving me error if i try to assign collection to a public variable
public $permissions;
public function mount() {
$this->permissions = Permission::get(['name', 'id', 'display_name'])->groupBy('display_name');
//if I assign do not assign it to public variable it worked
//e.g $permissions = Permission::get(['name', 'id', 'display_name'])->groupBy('display_name');
//but i need it in the view for looping.
//if i add ->toArray() or ->collect() it worked.
// e.g $this->permissions = Permission::get(['name', 'id', 'display_name'])->groupBy('display_name')->collect();
}
The Error:
Method Illuminate\Database\Eloquent\Collection::getMorphClass does not exist.
According to me: when Livewire tries to serialize the component data for transport to the frontend, it might be encountering difficulties with the grouped collection. To work around if I convert the grouped collection to an array before assigning it to the property, it worked but it is an array not collection. But this was not an issue in Livewire 2