Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.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

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
Php 通过artisan命令调用时请求参数丢失_Php_Laravel_Lumen_Laravel Artisan - Fatal编程技术网

Php 通过artisan命令调用时请求参数丢失

Php 通过artisan命令调用时请求参数丢失,php,laravel,lumen,laravel-artisan,Php,Laravel,Lumen,Laravel Artisan,在artisan命令中,使用参数创建请求以调用路由时,目标路由不接收请求参数 testcommand: <?php namespace App\Console\Commands; use Illuminate\Console\Command; use Laravel\Lumen\Http\Request; class TestCommand extends Command { /** * The name and signature of the console command.

在artisan命令中,使用参数创建请求以调用路由时,目标路由不接收请求参数

testcommand:

<?php

 namespace App\Console\Commands;

use Illuminate\Console\Command;
use Laravel\Lumen\Http\Request;

class TestCommand extends Command
{
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'route:run';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Command description';

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

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $date = [
        'username' => 'test',

    ];
    $tokenRequest = Request::create('/test', 'post', $date);
    $res = app()->handle($tokenRequest)->withHeaders(['Content-Type' => 'application/json']);
    $responseBody = json_decode($res->getContent());
    var_dump($responseBody);
}
}
另一个问题是管腔的缺陷。
当我们运行php artisan route:run in terminal时,目标路由没有包含参数。

第一个问题,为什么要在命令中发送请求?
php artisan
和Lumen?您是在混合Laravel和Lumen吗?@lagbox我们需要在pub/sub、命令订阅频道中使用参数调用路由,并且在接收数据时需要调用路由并将参数传递给该路由。您为什么需要调用路由?你不能从控制器中重构代码并直接调用它吗?您可以将复制的代码重构成另一个命令或动作类,并直接从控制器和命令调用它。
<?php

 namespace App\Http\Controllers;

 use Laravel\Lumen\Http\Request;

 class ExampleController extends Controller
 {
/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    //
}


public function test(Request $request)
{
    $this->validate($request,[
       'username'=>'required'
    ]);
    return $request->all();
}

 }
$router->post('/test','ExampleController@test');