nunomaduro / laravel-console-menu

🔘 Beautiful PHP CLI menus. Is a php-school/cli-menu wrapper for Laravel/Artisan Console Commands
MIT License
802 stars 40 forks source link

Method menu does not exist. #5

Closed crlcu closed 6 years ago

crlcu commented 6 years ago

Hi, I have just created a new console command:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    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");
    }
}

and I doesn't seem to work.

This is the error that I'm getting:

root@tpt:/var/www/html/tpt# php artisan test

In Macroable.php line 96:

  Method menu does not exist.

Any idea what's wrong ?

crlcu commented 6 years ago

Ah, got it, I wasn't required the right package.

jesus-animum3d commented 4 years ago

@crlcu How did you fix it?

jesus-animum3d commented 4 years ago

I solved this:

use NunoMaduro\LaravelConsoleMenu\Menu;

class menuCommand extends Command
{...
    public function handle()
    {
        $menu = new Menu('Pizza menu', [
            'Freshly baked muffins',
            'Freshly baked croissants',
            'Turnovers, crumb cake, cinnamon buns, scones',
        ])->open();

        $option = $menu
            ->disableDefaultItems()
            ->open();

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