How to get All input of POST in Laravel

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: A Comprehensive Guide on Retrieving All Input of POST Variables in Laravel Introduction: Laravel is an efficient PHP framework that offers developers powerful tools to build web applications efficiently. One such tool is the Request object, which enables the retrieval of input data from different HTTP request types. In this blog post, we discuss how to get all input of POST variables within a Laravel application, and provide examples using various methods. 1. Understanding the Request Class The Laravel's Request class is responsible for handling input from HTTP requests. It provides an easy way to access and manipulate incoming data. The class offers multiple ways to retrieve input from different forms of requests, such as GET, POST, PUT, DELETE, etc. We will focus on the POST request for this tutorial. 2. Using Request::all() in Laravel 5 The first method we will discuss is using the Request object's all() method to retrieve all input in a POST request. Here's an example of how it can be implemented:
public function add_question()
{
    return Request::all();
}
The above code will successfully return the entire input array for the current request. However, it is important to note that this may not be the most efficient method as it can potentially return sensitive data from the request, especially if there are any hidden inputs or cross-site scripting vulnerabilities. Be cautious when working with such methods and ensure you only retrieve necessary information. 3. Retrieving Specific Inputs Using Request Validation in Laravel 5.1+ Starting with Laravel 5.1, the framework introduced validation rules for request data which can be used to filter input and return only specific keys. To achieve this, create a request class that handles your form submission (e.g., AddQuestionRequest) within the app/Http/Requests folder:
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AddQuestionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|min:3', // Validation rule for title input field
            'question_text' => 'required' // Validation rule for question text input field
        ];
    }
}
Now, to retrieve the values of these specific inputs, you can use the following code in your controller:
public function add_question(AddQuestionRequest $request)
{
    // Access input data using `$request->input('title')` and `$request->input('question_text')`
}
Note that this approach ensures you only receive the data you need, reducing the risk of exposing sensitive information. Additionally, it also provides validation rules to ensure proper input values. 4. Using Laravel's Request Validation System in Modern Versions In modern Laravel versions (5.6 and above), the framework has further improved its request handling capabilities. The Request object now offers a with method for working with incoming data. Here's an example:
public function add_question(Request $request)
{
    // Access input data using `$request->input('title')` and `$request->input('question_text')`
}
Using Laravel's validation system, you can easily specify the request data to be handled and create a more secure application. Conclusion: While there are several ways to get all input of POST variables in a Laravel application, it is essential to use the most efficient and secure methods available. Always make sure to handle sensitive data with caution and ensure proper validation rules are implemented. In this blog post, we've covered three different techniques for obtaining input from POST requests - Request::all() in older versions of Laravel, request validation using request classes in Laravel 5.1+, and more modern approaches available in recent Laravel versions. By following best practices, you can develop secure applications while making use of powerful framework tools like the Request class.