Laravel 5 - 如何从Artisan Command运行Controller方法?

iSS*_*iSS 7 php command controller laravel artisan

我需要控制器中的一些代码每十分钟运行一次.用Scheduler和容易Commands.但.我创建了一个Command,用Laravel Scheduler(in Kernel.php)注册它,现在我无法实例化Controller.我知道这是解决这个问题的错误方法,但我只需要快速测试.为了达到这个目的,有没有办法,请注意一个黑客的方式?谢谢.

更新#1:

Command:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Http\Controllers\StatsController;


class UpdateProfiles extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update-profiles';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Updates profiles in database.';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        StatsController::updateStats('<theProfileName>');
    }
}
Run Code Online (Sandbox Code Playgroud)

updateStats() 方法 StatsController.php

public static function updateStats($theProfileName) { 
   // the body
}
Run Code Online (Sandbox Code Playgroud)

这返回一个FatalErrorException:

[Symfony\Component\Debug\Exception\FatalErrorException] 
syntax error, unexpected 'if' (T_IF)
Run Code Online (Sandbox Code Playgroud)

更新#2:

事实证明我的updateStats()方法中有一个拼写错误,但@ alexey-mezenin的回答就像一个魅力!它也足以导入ControllerCommand:

use App\Http\Controllers\StatsController;
Run Code Online (Sandbox Code Playgroud)

然后按照正常的方式初始化它:

public function handle() {
   $statControl        = new StatsController;
   $statControl->updateStats('<theProfileName>');
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*nin 5

尝试use Full\Path\To\Your\Controller;在命令代码中使用并静态使用方法:

public static function someStaticMethod()
{
    return 'Hello';
}
Run Code Online (Sandbox Code Playgroud)

在您的命令代码中:

echo myClass::someStaticMethod();
Run Code Online (Sandbox Code Playgroud)