简体   繁体   中英

Laravel - add to GET parameter manually

Is there a way of adding to the GET parameter in Laravel, so that I can use

$request->input('param')

I've tried setting it in $_GET and did not pick up. Basically I want to set something in to the HTTP Request's GET parameter set, so that I can retrieve it as if it was pass in as a GET params. (Which is sometimes sent)

You can add params to your Request $request object like this

public function missingSomeParam(Request $request)
{
    // let's think you don't have "name" param sent in $request
    // set it this way
    $name = "Dummy Name";
    $request->request->add(['name' => $name]);
    dd($request->all());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM