Creating a request object with $myRequest = new Request(); creates the object with method = 'GET'. You can check your request's method with $myRequest->getMethod(). As the request property holds data for POST requests you cannot use $myRequest->request->add() by default. First you have to set the request's method to POST:
$myRequest = new \Illuminate\Http\Request();
$myRequest->setMethod('POST');
$myRequest->request->add(['foo' => 'bar']);
dd($request->foo);
By the way using $myRequest->query->add() you can add data to a GET request.
--
轉自 https://stackoverflow.com/questions/40262947/create-a-laravel-request-object-on-the-fly
文章標籤
全站熱搜
