Laravel Request::all() Should Not Be Called Statically

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel Request::all() Should Not Be Called Statically Body: In Laravel, when working with controllers, one common error that developers encounter is an attempt to call `$input = Request::all();` on a `store()` method within their controller. However, this causes the following issue: "Non-static method Illuminate\Http\Request::all() should not be called statically, assuming $this from incompatible context." The question here is how to fix this problem and use Laravel's request data correctly while maintaining the best practices. To understand this error, let us first examine what Request::all() does: It returns an associative array containing all the key-value pairs submitted through an HTTP request as form data or query parameters. In other words, it gathers input from different parts of the request and combines them into a single array. Now, let's address the error itself. As mentioned in the error message, Request::all() should not be called statically. Static methods can be accessed without an instance or class reference by calling their names directly, but non-static methods require the existence of an object that 'belongs to' a certain class or namespace. In this case, the Illuminate\Http\Request class has a non-static method named all(). To address the error, there are two common solutions: 1. Use the Laravel Container to get access to a specific Request instance - Laravel provides an IoC (Inversion of Control) container for managing dependencies. To retrieve a request object from this container, you can use the following code: `$input = app()->make('\Illuminate\Http\Request')->all();` This ensures that you're calling the non-static method on an instance that belongs to the correct context. 2. Use the Illuminate\Support\Facades::request() helper function - Laravel also provides a shortcut function called `request()`, which is defined in the Illuminate\Support\Facades namespace and internally uses the request object from the IoC container. You can use it as follows: `$input = request()->all();` This methodology simplifies the process of getting access to request data while avoiding static calls. While these solutions address the error, you should also consider best practices for working with request data in Laravel: - Use validation to ensure input data is clean and matches expected formats before proceeding. - Keep your controller methods lean and focused on their main function. Consider separating data handling and validation logic into dedicated services or facades. This promotes better code organization and makes the code more readable. - Always name your route parameters clearly, so you can easily access them later within your method via `route()` helpers or directly from the request object. In conclusion, when working with Laravel controllers and request data, it is crucial to avoid static calls of non-static methods like Request::all(). Instead, utilize the Laravel Container, request facades, and proper code organization to ensure the best practices are followed. By doing so, you not only eliminate errors but also improve your application's overall structure and readability.