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 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复