2014-05-04 7 views
7

परिभाषित नहीं है मैं कारीगरकमान अपवाद

$ php artisan command:make NeighborhoodCommand 

के साथ एक कमांड बनाया इस फ़ाइल app/commands/NeighborhoodCommand.php

कोड के स्निपेट बनाया। मैं name मूल्य संशोधित और 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 
    } 
} 

लेकिन तब जब मैं

$ php artisan neighborhood 

साथ कमांड चलाने का प्रयास है कि मैं इस त्रुटि मिलती है:

[InvalidArgumentException] 
Command "neighborhood" is not defined. 

उत्तर

23

Laravel 5.5 +

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

यदि आप चाहें, तो आप मैन्युअल रूप से अपने आदेश पंजीकृत कर सकते हैं। लेकिन एल 5.5 आपको आलसी लोड करने का विकल्प देता है। 5

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

संपादित अपने app/Console/Kernel.php फ़ाइल

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

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

Laravel और $commands सरणी के लिए अपने आदेश जोड़ें: आप एक पुराने संस्करण से उन्नयन कर रहे हैं, तो आपके कर्नेल के लिए इस विधि को जोड़ने :

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

Laravel 4

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

app/start/artisan.php को यह पंक्ति जोड़ दें:

Artisan::add(new NeighborhoodCommand); 
+1

प्लस के लिए विनम्र और एक अच्छा जवाब किया जा रहा है। मुझे 1000 बार हुआ! –

संबंधित मुद्दे