MorphToMany Select Relationship

Im getting completely frazzled with MorphToMany setup in a select instance.

I have a User that Morphs to Many Organisation and Product. Im trying to merge the items into a single Select, and I have it working, except when trying to edit a user, I cant get it to show the already existing records as already selected values.

I found this function
                    ->loadStateFromRelationshipsUsing(function (User $record) {
                        // Retrieve the organisation IDs managed by the user
                        $organisationIds = $record->morphedOrganisations()->pluck(
                            (new Organisation())->getQualifiedKeyName()
                        )->toArray();

                        // Retrieve the product IDs managed by the user
                        $productIds = $record->morphedProducts()->pluck(
                            (new Product())->getQualifiedKeyName()
                        )->toArray();

                        dd(array_merge($organisationIds, $productIds));

                        // Combine both arrays of IDs
                        return array_merge($organisationIds, $productIds);
                    })

I can get the array of ids, but im not sure what im missing at displaying them as the selected values
Solution
Ah, I figured it out, I don't return it, I attach to $component->state();
Was this page helpful?