when in artisan command create request with parameter to call a route, destination route dose not receive request parameters.
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);
}
}
and my controller is:
<?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();
}
}
and route is:
$router->post('/test','ExampleController@test');
another things is default of lumen. when we run php artisan route:run in terminal, destination route does not get included parameter.