Php 拉威尔:调度器找不到我的控制器

Php 拉威尔:调度器找不到我的控制器,php,laravel,yii,Php,Laravel,Yii,我在命令中创建了一个新类。在文件夹App\Console\Commands中 <?php namespace App\Console\Commands; use Illuminate\Console\Command; class Schedular extends Command { /** * The name and signature of the console command. * * @var string */ p

我在命令中创建了一个新类。在文件夹App\Console\Commands中

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

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

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

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
         return $schedule->call('Schedular@schedule')->everyMinute();
    }
}

<>或者我应该创建一个与控制器具有相同功能的新类吗?

您应该将控制器看作是应用程序的<强>传输层< /强>。任何实际的功能逻辑都应该进入您的域类

尝试以使用控制器功能的方式重构控制器功能,例如服务类。然后创建一个同样使用相同服务类的命令类,提供另一种触发功能的方法

这样,您就可以将功能封装在服务类中。控制器类和命令类都只是将该类用作传输手段;HTTP请求和CLI命令


重构完成后,您可以将命令安排为每分钟运行一次

控制器用于web请求,您需要创建控制台命令类您确定要在此处使用
受保护的功能吗?
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use \App\Controllers;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\Schedular'
    ];

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

       return $schedule->call('')->everyMinute();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}
 return $schedule->call('')->everyMinute();