Skip to content

Feature suggestion: toggles #175

@Plytas

Description

@Plytas

Laravel Prompts Version

n/a

Laravel Version

n/a

PHP Version

n/a

Operating System & Version

n/a

Terminal Application

n/a

Description

Similar to confirm() and/or multiselect() it would be nice to have toggle()/toggles() prompt, that would list options and and let you turn them off/on. The result would be an array of all options as keys and true/false as their values.

It's possible to do this using multiselect(), but you have to map the response yourself and visual toggle could be different.

Imagine a NotificationSettings model that stores bool flags in different columns.

Pseudo code:

$notificationSettings = NotificationSettings::first();

$options = [
    'app' => 'In app',
    'email' => 'By email',
    'mobile' => 'Mobile push notifications',
];

$defaults = array_map($options, fn(string $value, string $key) => $notificationSettings?->$key ?? false);
// [
//     'app' => true,
//     'email' => false,
//     'mobile' => true,
// ]

$settings = toggles(
    label: 'How would you like to receive notifications?',
    options: $options,
    defaults: $defaults
);
// [
//     'app' => true,
//     'email' => false,
//     'mobile' => false,
// ]

$notificationSettings->update($settings);

Steps To Reproduce

Nothing, just a feature suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions