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

displayUsing() doesn't display anything #223

Open
frederiksimon opened this issue Jul 4, 2023 · 1 comment
Open

displayUsing() doesn't display anything #223

frederiksimon opened this issue Jul 4, 2023 · 1 comment

Comments

@frederiksimon
Copy link

When using displayUsing function on multiselect field, it doesn't display the returned value in resource listing.
Editing form has correct values for the pivot field, only issue is with the displayed values.

My code:

            `MorphToMany::make(__('genericProperties'), 'genericProperties', config('eshop.eshop_generic_property_resource'))
                ->fields(function($request, $field) {
                    return [
                        \Outl1ne\MultiselectField\Multiselect::make(__('genericPropertyValues'), 'with_generic_property_values')
                            ->dependsOn(['genericProperties'], function (\Outl1ne\MultiselectField\Multiselect $field, NovaRequest $request, FormData $formData) {
                                $genericPropertyId = (int) $formData->resource(GenericProperty::uriKey());

                                $options = \Models\GenericPropertyValue::query()
                                    ->where('generic_property_id', '=', $genericPropertyId)
                                    ->get()->mapWithKeys(function ($item) {
                                        return [$item->id => $item->value];
                                    })
                                    ->toArray();

                                $field->options($options);
                            })
                            ->displayUsing(function () use ($field) {

                                $genericPropertyValuesIds = json_decode($field->pivot->with_generic_property_values);

                                $genericPropertyValues = config('eshop.eshop_generic_property_value_model')::query()
                                    ->whereIn('id', $genericPropertyValuesIds)
                                    ->get();

                                $displayText = '';

                                foreach ($genericPropertyValues as $value) {
                                    $displayText = $displayText . $value->value . ' | ';
                                }

                                return rtrim($displayText, ' | ');
                            })
                    ];
                }),`
@Tarpsvo
Copy link
Collaborator

Tarpsvo commented Aug 10, 2023

Heya! I'd be really grateful if you'd help with debugging this and submit a PR if you find out what's causing displayUsing to not work. I currently don't have the time to look into this. :( Sorry.

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

2 participants