How to get All input of POST in Laravel

后端 未结 8 927
不知归路
不知归路 2021-02-03 17:10

I am using Laravel 5 and trying to get all input of POST variable in controller like this-

public function add_question()
{
    return Request::all();
}
<         


        
8条回答
  •  灰色年华
    2021-02-03 17:46

    For those who came here looking for "how to get All input of POST" only

    class Illuminate\Http\Request extends from Symfony\Component\HttpFoundation\Request which has two class variables that store request parameters.

    public $query - for GET parameters

    public $request - for POST parameters

    Usage: To get a post data only

    $request = Request::instance();
    $request->request->all(); //Get all post requests
    $request->request->get('my_param'); //Get a post parameter
    

    Source here

    EDIT

    For Laravel >= 5.5, you can simply call $request->post() or $request->post('my_param') which internally calls $request->request->all() or $request->request->get('my_param') respectively.

提交回复
热议问题