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

function multiselect in windows return index as options but in ubuntu returns value of options #178

Closed
HusseinIbrahem opened this issue Dec 14, 2024 · 5 comments

Comments

@HusseinIbrahem
Copy link

Laravel Prompts Version

0.1.25

Laravel Version

10.48.23

PHP Version

8.2

Operating System & Version

windows 10 , ubutnu

Terminal Application

power shel

Description

this code :

$folders = multiselect(
            label: 'select folders.',
            options: $uploadDirectories,
            required: true,
        );

in windows returns key of selected but in ubuntu returns the values nad i have to write this code to prevent any error in any operating system:

if (is_numeric($folders[0])) {
            $this->selectedDirectories = array_values(array_intersect_key(
                $uploadDirectories,
                array_flip($folders)
            ));
        }
        else {
            $this->selectedDirectories = $folders;
        }

Steps To Reproduce

nothing

@jessarcher
Copy link
Member

What type of keys does $uploadDirectories have? Are they strings or integers? If integers, are they sequential starting from 0?

@HusseinIbrahem
Copy link
Author

HusseinIbrahem commented Dec 14, 2024 via email

@jessarcher
Copy link
Member

I'm having trouble replicating this one. When you say Windows, are you talking about native Windows (i.e. php.exe) or WSL? I'm assuming you're talking about native Windows where Prompts falls back to Symfony console components.

To try to replicate this, I've created a command with the following:

<?php

dump(
    multiselect('test', [
        'upload/users',
        'upload/profiles',
    ], required: true)
);

Prompt::fallbackWhen(true); // Simulate running on Windows using the Symfony console fallback.

dump(
    multiselect('test', [
        'upload/users',
        'upload/profiles',
    ], required: true)
);

When running the command, I tried selecting all possible combinations (the first option, the second option, and both options) and always received the values:

image

Are you sure the array you pass in has sequential numeric keys starting from 0? If you pass it through array_filter(), then it may not have sequential keys any longer, in which case Prompts and the Symfony fallback should return the key instead of the value.

@HusseinIbrahem
Copy link
Author

Hi, i'm talking about native Windows. i'm using nwidart/laravel-modules package, i'm write this code in command

        $a = [
            'upload/users',
            'upload/profiles',
        ];
        dump($a);
        dump(
            multiselect('test', $a, required: true)
        );

        Prompt::fallbackWhen(true); // Simulate running on Windows using the Symfony console fallback.

        dump(
            multiselect('test', $a, required: true)
        );

and the output is same:
image
also run this code in laravle command without module package and the result is same. my best regards.

@jessarcher
Copy link
Member

Thanks @HusseinIbrahem.

I've just realised the problem is with the older version of Laravel you're using.

This issue was fixed in the following PRs:

Upgrading to the latest version of Laravel should fix the issue for you.

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