2017-04-12 5 views
-1

나는이 자습서 다음하고 작업 일정 Laravel에 존재하지 않는하기 : https://www.sitepoint.com/managing-cronjobs-with-laravel/오류 명령은

하지만 명령 줄 php artisan make:list에 입력 할 때 내가

[ReflectionException] 
    Class App\Console\Command\Test123 does not exist 

어떻게 문제보다 해결하기 위해 오류 메시지가? 내가 도대체 ​​뭘 잘못하고있는 겁니까? 당신이 Test123 클래스를 만든 후에는

composer dumpautoload 

을 깜빡 때문에

Test123.php

<?php 

namespace App\Console\Commands; 

use Illuminate\Console\Command; 
use Carbon\Carbon; 

use Response; 
use Config; 
use DB; 
use GuzzleHttp\Exception\GuzzleException; 
use GuzzleHttp\Client; 

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

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

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

    /** 
    * Execute the console command. 
    * 
    * @return mixed 
    */ 
    public function handle() 
    { 
      $parameters = [ 
     'attribute1' => 'val1', 
     'attribute2' => 'val2', 
     '_token' => Config::get('app.secret') 
     ]; 
     $formattedParameters = http_build_query($parameters); 
     $statusCode = 200; 
     $url = "url?{$formattedParameters}"; 

     $client = new Client(); 
     $res = $client->get($url); 

     $jsonArray = json_decode($res->getBody(),true); 
     $field1= $jsonArray['field1']; 

     DB::table('table_name')->insert(
    ['field1' => $field1] 
); 
    } 
} 

Kernel.php는

<?php 

namespace App\Console; 

use Illuminate\Console\Scheduling\Schedule; 
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; 
use Carbon\Carbon; 

use Response; 
use Config; 
use DB; 
use GuzzleHttp\Exception\GuzzleException; 
use GuzzleHttp\Client; 


class Kernel extends ConsoleKernel 
{ 
    /** 
    * The Artisan commands provided by your application. 
    * 
    * @var array 
    */ 
    protected $commands = [ 
    \App\Console\Command\Test123::class, 
    ]; 

    /** 
    * Define the application's command schedule. 
    * 
    * @param \Illuminate\Console\Scheduling\Schedule $schedule 
    * @return void 
    */ 
    protected function schedule(Schedule $schedule) 
    { 

     $schedule->command('abcd')->everyMinute(); 



    } 

    /** 
    * Register the Closure based commands for the application. 
    * 
    * @return void 
    */ 
    protected function commands() 
    { 
     require base_path('routes/console.php'); 
    } 
} 
+0

@apokryfos 튜토리얼에 따라 HappyBirthday라는 파일을 새로 만들었지 만 HappyBirthday도 존재하지 않습니다. App \ Console \ Command \ Test123 :: class를 제거하면 다른 명령을 실행할 수 있습니다. 그러나 기억에서 모든 것을 없애는 방법이 있습니까? 캐시 등을 지우십시오. –

답변

1

두 가지 문제점이 있습니다.

먼저 Kernel.php 파일에,이 있습니다

protected $commands = [ 
    App\Console\Command\Test123::class, 
]; 

백 슬래시 (\)는 현재 네임 스페이스에 지정된 클래스의 상대를 찾습니다으로 클래스 이름을 시작하지 않았기 때문에를 Kernel.php의 경우 App\Console입니다. 그래서 귀하의 오류는 클래스 App\Console\App\Console\Command\Test123을 찾을 수 없다는 내용입니다.

그래서, 당신은에 있음을 변경하는 경우 :

protected $commands = [ 
    \App\Console\Command\Test123::class, 
]; 

그것은 이제 루트 네임 스페이스에서 \App\Console\Command\Test123을 찾기 위해 시도합니다.

두 번째 문제가 발생합니다. Test123 클래스에서 App\Console\Command이 아닌 App\Console\Commands으로 지정된 네임 스페이스가 있습니다 (추가 s이 있음).

파일이 app\Console\Commands 디렉토리에있는 경우 네임 스페이스가 정확하며 올바른 클래스를 찾으려면 Kernel.php 파일을 수정해야합니다. 파일이 app\Console\Command 디렉토리에 있으면 네임 스페이스가 올바르지 않으므로 Test123 클래스의 네임 스페이스 선언을 수정해야합니다.

+0

현재 내 Test123.php 파일은 app/Console/Commands 폴더에 있습니다.이 파일은 kernel.php의 현재 코드입니다. $ commands = [ \ App \ Console \ Command \ Test123 :: class, ]; 이제 무엇을 변경해야합니까? –

+0

네임 스페이스를 수정하고 여분을 제거했는데 [Symfony \ Component \ Console \ Exception \ RuntimeException] 오류가 발생합니다. 인수가 부족합니다 (누락 : "이름"). –

+0

php artisan abcd를 실행하면 코드가 작동하지만 php artisan make : list가 아직 작동하지 않는 것 같습니다. 내가 주석 오류보다 높습니다. –

0

I'm getting

Class App\Console\App\Console\Command\Test123 does not exist

How to fix above issue?

99,9 %에서 그것은이다 . 지금 당장 해. 그러면 괜찮을거야.

편집

당신이 쇼에게 내가 대신 App\Console\Command\Test123을해야 거의 확신으로 나에게 냄새 클래스의 전체 이름 공간을보고있는 오류 메시지입니다. 그렇다면 배열을 다음과 같이 편집하십시오.

protected $commands = [ 
    \App\Console\Command\Test123::class, 
]; 
+0

내가 언급 한대로 작곡가 dumpautoload 않았다하지만 작동하지 않는 것.같은 오류 –

+0

편집 된 답변보기 –

+0

이것은 아주 이상합니다. 위와 같이 변경했는데 php artisan이나 php artisan dump-autoload 또는 php artisan dumpautoload를 실행할 수 없습니다. 나는 일한 작곡가 덤프 - 자동로드를 했어. 그러나 나는 내가 꽤 붙어 있다고 생각한다. php artisan serve를 실행할 수 없습니다 :/ –