我正试图在Laravel 5中以不同的、用户配置的时间间隔运行Artisan控制台命令。我已经构建了控制台命令,并有一个数据库(使用Eloquent模型),其中包含"运行频率"配置值。
在App'Console'Kernel.php
的schedule()
函数中,我想从数据库中取出这个值,并根据这个值在需要时运行命令。
当使用带有或不带有use DB;
的DB::table()...
时,我会收到Fatal error: Class 'DB' not found
,如果我也尝试使用Cache::...
函数,也会发生同样的情况。
我假设IoC容器不能从App'Console'Kernel.php
文件的schedule()
函数中访问。有人有类似的方法并找到了一个优雅的解决方案吗?
我的简化代码是:
<?php namespace App'Console;
use Cache;
use Illuminate'Console'Scheduling'Schedule;
use Illuminate'Foundation'Console'Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* Define the application's command schedule.
*
* @param 'Illuminate'Console'Scheduling'Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$settings = Cache::get('settings');
}
错误:
php artisan schedule:run
PHP Fatal error: Class 'Cache' not found in /home/vagrant/projects/project/dir/api/app/Console/Kernel.php on line 26
任何帮助都将不胜感激
Taylor在5.0.21(Git Commit)中已经修复了这一问题,因此任何遇到相同问题的人都可以运行composer update
来获得该框架的最新版本,该版本将允许您使用
Use DB;
Use Cache;
等正常