Build interactive menus

Interactive menus in console applications are very powerful. They provide a simple interface that requires little interaction. With Laravel Zero, you can use the menu method to create beautiful menus:

Using menus in the console may sound silly, but is fantastic! Your users don't need to type the number corresponding to their choice any more. They can just use the arrows on their keyboard to make their selection!


Create your first menu by copy pasting the code below in your commands handle function.

$option = $this->menu('Pizza menu', [
    'Freshly baked muffins',
    'Freshly baked croissants',
    'Turnovers, crumb cake, cinnamon buns, scones',

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

When you now run your command your output should be similar to this image:

Changing the appearance

The appearance of the menu can be set with a fluent API. What if we like a green font on a black background? The code below shows you how to do just that and some extras.

$this->menu($title, $options)
    // remove exit button with
    // ->disableDefaultItems()
    ->addLineBreak('<3', 2)
    ->addStaticItem('AREA 2')

Behind the scenes, the menu method uses the nunomaduro/laravel-console-menu package. You can find more details on how to use the menu method there.