![[Laravel][轉] Create a Laravel [Laravel][轉] Create a Laravel](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/dizzy03/1697792328-736961951-g_n.png&width=600&height=225)
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