dongwen7187 2016-12-27 17:38
浏览 27
已采纳

ReflextionException,Class不存在(Laravel命令)

I'm using Laravel 5.3. I have wrote 2 laravel commands but when I call they from the window's cmd, just one works fine(command:name), the other(command:delayedPayment) gives me the next error:

enter image description here

But when I comment the DelayedPayment call, it works fine.

app/Console/Kernel.php

<?php
   namespace App\Console;

   use Illuminate\Console\Scheduling\Schedule;
   use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
   class Kernel extends ConsoleKernel
   {
    protected $commands = [
        'App\Console\Commands\GenerateInvoice',
        'App\Console\Commands\DelayedPayment',
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('command:name')->everyMinute();
        $schedule->command('command:delayedPayment')->everyMinute();
    }

    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

app/Console/Commands/DelayedPayment.php

namespace App\Console\Commands;
namespace App\Http\Business;
namespace App\Http\Entities;

use Illuminate\Console\Command;

class DelayedPayment extends Command
{
    protected $signature = 'command:delayedPayment';

    protected $description = 'Command description';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        ...

    }
}

Its necessary to do something else?.Thank you in advance!

  • 写回答

2条回答 默认 最新

  • doubaisui2526 2016-12-27 17:40
    关注

    As according to your code, you've mentioned 3 namespaces inside DelayedPayment.php file, you should mention only one namespace per file at the top:

    namespace App\Console\Commands; // <-------- Use only one namespace per file
    
    use Illuminate\Console\Command;
    
    class DelayedPayment extends Command
    {
        protected $signature = 'command:delayedPayment';
    
        protected $description = 'Command description';
    
        public function __construct()
        {
            parent::__construct();
        }
    
        public function handle()
        {
            ...
    
        }
    }
    

    Read more about PHP Namespacing Docs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA