// Show only POST data
$request->post(); // DI
request()->post(); // global method
Request::post(); // facade
// Show only GET data
$request->query(); // DI
request()->query(); // global method
Request::query(); // facade
// Show all data (i.e. both GET and POST data)
$request->all(); // DI
request()->all(); // global method
Request::all(); // facade
Try this :
its better to use the Dependency than to attache it to the class.
or if you prefer using input variable use
you can now use the global request method provided by laravel
for example to get the first_name of a form input.
You can get all post data into this function :-
and if you want specific filed then use it :-
There seems to be a major mistake in almost all the current answers in that they show BOTH GET and POST data. Not ONLY POST data.
The issue with your code as the accepted answer mentioned is that you did not import the facade. This can imported by adding the following at the top:
You can also use the global request method like so (mentioned by @Canaan Etai), with no import required:
However, a better approach to importing
Request
in a controller method is by dependency injection as mentioned in @shuvrow answer:More information about DI can be found here:
In either case, you should use:
For those who came here looking for "how to get All input of POST" only
class
Illuminate\Http\Request
extends fromSymfony\Component\HttpFoundation\Request
which has two class variables that store request parameters.public $query
- for GET parameterspublic $request
- for POST parametersUsage: To get a post data only
Source here
You can use it
without
import Illuminate\Http\Request
ORuse Illuminate\Support\Facades\Request
OR other.