2014-05-04 16 views
7

ho creato un comando con Artisancomando non è definito eccezione

$ php artisan command:make NeighborhoodCommand 

Questo ha creato il file app/commands/NeighborhoodCommand.php

frammento del codice. Ho modificato il valore name e riempito nella funzione fire()

<?php 

use Illuminate\Console\Command; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Input\InputArgument; 

class NeighborhoodCommand extends Command { 

    protected $name = 'neighborhood'; 

    public function fire() 
    { 
     // my code 
    } 
} 

Ma poi quando si tenta di eseguire il comando con

$ php artisan neighborhood 

ottengo questo errore:

[InvalidArgumentException] 
Command "neighborhood" is not defined. 

risposta

23

laravel 5.5 +

https://laravel.com/docs/5.5/artisan#registering-commands

Se lo desideri, puoi continuare a registrare manualmente i tuoi comandi. Ma L5.5 ti dà la possibilità di caricarli pigri. Se si esegue l'aggiornamento da una versione precedente aggiungere questo metodo per il vostro kernel:

/** 
* Register the commands for the application. 
* 
* @return void 
*/ 
protected function commands() 
{ 
    $this->load(__DIR__ . '/Commands'); 

    require base_path('routes/console.php'); 
} 

laravel 5

http://laravel.com/docs/5.4/artisan#registering-commands

Modificare il file app/Console/Kernel.php e aggiungere il comando per l'array $commands :

protected $commands = [ 
    Commands\NeighborhoodCommand::class, 
]; 

laravel 4

http://laravel.com/docs/4.2/commands#registering-commands

aggiungere questa riga a app/start/artisan.php:

Artisan::add(new NeighborhoodCommand); 
+1

Plus per essere umili e una buona risposta. Mi è successo 1000 volte! –