[英]laravel: scheduler cant find my controller
我在command。文件夾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();
}
}
並在kern.php中,我編寫了以下代碼
<?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();
還是應該創建具有與控制器相同功能的新類?
您應該將控制器僅視為應用程序的傳輸層 。 任何實際的功能邏輯都應納入您的域類。
嘗試使用消耗服務的方式重構控制器功能。 然后創建一個也使用相同服務類的命令類,提供另一種觸發功能的方法。
這樣,您就可以將功能封裝在服務類中。 控制器類和命令類都只是在使用該類作為傳輸手段。 HTTP請求和CLI命令。
完成重構后,您可以安排命令每分鍾運行一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.