我正在尝试以不同的用户配置的时间间隔在 Laravel 5 中运行 Artisan 控制台命令。我已经构建了控制台命令,并拥有一个包含“运行频率”配置值的数据库(具有 Eloquent 模型)。
内schedule()
的函数App\Console\Kernel.php
我想从数据库中提取该值,并根据该值在需要时运行命令。
我收到一个Fatal error: Class 'DB' not found
使用时DB::table()...
有还是没有use DB;
,如果我尝试使用也会发生同样的情况Cache::...
功能也。
我假设 IoC 容器无法从内部访问schedule()
的函数App\Console\Kernel.php
文件。有没有人有类似的情况并找到了一个优雅的解决方法?
我的简化代码是:
<?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 提交 https://github.com/laravel/framework/commit/6a9aa29278e13274549d8205f2b21a2d2cb70e98)所以遇到同样问题的任何人都可以运行composer update
获取最新版本的框架,这将允许您使用
Use DB;
Use Cache;
像往常一样
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)