[Laravel][轉] Create a Laravel

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

arrow
arrow
    全站熱搜

    dizzy03 發表在 痞客邦 留言(0) 人氣()