How to get All input of POST in Laravel

后端 未结 8 1107
不知归路
不知归路 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:54

    its better to use the Dependency than to attache it to the class.

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

    or if you prefer using input variable use

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

    you can now use the global request method provided by laravel

    request()
    

    for example to get the first_name of a form input.

    request()->first_name
    // or
    request('first_name')
    

提交回复
热议问题