PHPackages                             nunomaduro/laravel-console-menu - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. nunomaduro/laravel-console-menu

ActiveLibrary[CLI &amp; Console](/categories/cli)

nunomaduro/laravel-console-menu
===============================

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

v3.7.0(2mo ago)815412.0k—1.5%39[1 issues](https://github.com/nunomaduro/laravel-console-menu/issues)[1 PRs](https://github.com/nunomaduro/laravel-console-menu/pulls)20MITPHPPHP ^8.1CI passing

Since Jan 28Pushed 2mo ago21 watchersCompare

[ Source](https://github.com/nunomaduro/laravel-console-menu)[ Packagist](https://packagist.org/packages/nunomaduro/laravel-console-menu)[ Fund](https://www.paypal.com/paypalme/enunomaduro)[ GitHub Sponsors](https://github.com/nunomaduro)[ RSS](/packages/nunomaduro-laravel-console-menu/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (18)Used By (20)

 [![](docs/example.png)](docs/example.png)

 [![Static Analysis](https://camo.githubusercontent.com/86839df14d045e65ecd36d6c3326d3e41e16b7c1311e8b452b991978319466a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e756e6f6d616475726f2f6c61726176656c2d636f6e736f6c652d6d656e752f7374617469632e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d737461746963253230616e616c79736973)](https://github.com/nunomaduro/laravel-console-menu/actions/workflows/static.yml) [![Latest Stable Version](https://camo.githubusercontent.com/d3e0b629d644fc3daa1329cff09b26af7b9ae4095c9e8978d20fed6aebf52a52/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6c61726176656c2d636f6e736f6c652d6d656e752f762f737461626c652e737667)](https://packagist.org/packages/nunomaduro/laravel-console-menu) [![License](https://camo.githubusercontent.com/a650a7fcd6190ce0f4114d1688ee7d93cb7dc4af4d2c0b8114c631128a6b9c54/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6c61726176656c2d636f6e736f6c652d6d656e752f6c6963656e73652e737667)](https://packagist.org/packages/nunomaduro/laravel-console-menu)

About Laravel Console Menu
--------------------------

[](#about-laravel-console-menu)

Laravel Console Menu was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a [php-school/cli-menu](https://github.com/php-school/cli-menu) wrapper for Laravel Console Commands.

Installation
------------

[](#installation)

> **Requires [PHP 8.1+](https://php.net/releases)**

Require Laravel Console Menu using [Composer](https://getcomposer.org):

```
composer require nunomaduro/laravel-console-menu
```

Usage
-----

[](#usage)

### Quick Setup

[](#quick-setup)

```
class MenuCommand extends Command
{
    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $option = $this->menu('Pizza menu', [
            'Freshly baked muffins',
            'Freshly baked croissants',
            'Turnovers, crumb cake, cinnamon buns, scones',
        ])->open();

        $this->info("You have chosen the option number #$option");
    }
}
```

### Setup with a question

[](#setup-with-a-question)

 [![](docs/example_with_question.png)](docs/example_with_question.png)

```
class MenuCommand extends Command
{
    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $option = $this->menu('Pizza menu')
                    ->addOption('mozzarella', 'Mozzarella')
                    ->addOption('chicken_parm', 'Chicken Parm')
                    ->addOption('sausage', 'Sausage')
                    ->addQuestion('Make your own', 'Describe your pizza...')
                    ->addOption('burger', 'Prefer burgers')
                    ->setWidth(80)
                    ->open();

        $this->info("You have chosen the text option: $option");
    }
}
```

### Setup with advanced option, in this case, a password

[](#setup-with-advanced-option-in-this-case-a-password)

 [![](docs/example_with_password.png)](docs/example_with_password.png)

```
class MenuCommand extends Command
{
    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $menu = $this->menu('Pizza menu')
                    ->addOption('mozzarella', 'Mozzarella')
                    ->addOption('chicken_parm', 'Chicken Parm')
                    ->addOption('sausage', 'Sausage')
                    ->addQuestion('Make your own', 'Describe your pizza...');

        $itemCallable = function (CliMenu $cliMenu) use ($menu) {
            $cliMenu->askPassword()
                ->setValidator(function ($password) {
                    return $password === 'secret';
                })
                ->setPromptText('Secret password?')
                ->ask();

            $menu->setResult('Free spice!');

            $cliMenu->close();
        };
        $menu->addItem('Add extra spice for free (password needed)', $itemCallable);

        $option = $menu->addOption('burger', 'Prefer burgers')
            ->setWidth(80)
            ->open();

        $this->info("You have chosen the text option: $option");
    }
}
```

### Appearance

[](#appearance)

Available colors: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`.

```
  $this->menu($title, $options)
      ->setForegroundColour('green')
      ->setBackgroundColour('black')
      ->setWidth(200)
      ->setPadding(10)
      ->setMargin(5)
      ->setExitButtonText("Abort") // remove exit button with ->disableDefaultItems()
      ->setTitleSeparator('*-')
      ->addLineBreak('
