Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自控制台命令的Laravel Run函数_Laravel_Controller_Console_Command_Execute - Fatal编程技术网

来自控制台命令的Laravel Run函数

来自控制台命令的Laravel Run函数,laravel,controller,console,command,execute,Laravel,Controller,Console,Command,Execute,LARAVEL 5.2刚刚创建了名为“HelloWorld”的命令,下面是代码: <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Http\Controllers\HelloWorldController; class MakeImportsCommand extends Command { /** * The name and signature of t

LARAVEL 5.2刚刚创建了名为“HelloWorld”的命令,下面是代码:

 <?php

namespace App\Console\Commands;

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

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Say Hello World Controller';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        return $this -> helloWorld();

    }
}
当我通过路由方法运行控制器时,它可以工作,但我想通过控制台命令运行它。这是我在控制台上的命令:php artisan helloworld。我得到了一个错误:

 [Symfony\Component\Debug\Exception\FatalErrorException]Call to undefined method App\Console\Commands\HelloWorldCommand::helloWorld()
我的问题是:有没有办法通过命令控制台调用这个函数?怎么用? 提前谢谢你

解决了! 我刚刚放置了handle controller的类名,并按如下方式调用了该函数:

$x = new HelloWorldController(); 
echo $x->helloWorld();
成功了

 [Symfony\Component\Debug\Exception\FatalErrorException]Call to undefined method App\Console\Commands\HelloWorldCommand::helloWorld()
$x = new HelloWorldController(); 
echo $x->helloWorld();