Request in Laravel 12
When we start working with Laravel, one of the most important concepts is the request. Almost everything in a web application begins with a request. when a user opens a page, submits a form, uploads a file or sends data using AJAX.
In this tutorial, we will cover everything you need to know about requests in Laravel step by step. We’ll also explain related concepts like the request lifecycle, handling AJAX requests, cURL requests, form request validation and more.
What is a Request in Laravel?
A request in Laravel simply represents the HTTP request coming from the client (browser, mobile app, or API). Laravel provides the Illuminate\Http\Request class to interact with request data.
For example:
Laravel Request Lifecycle

Before learning how to handle requests, it’s good to understand how they actually work inside Laravel.
The Laravel request lifecycle goes like this:
-
User sends request – A user opens
example.com/postsor submits a form. -
Public/index.php – Every request first hits the
public/index.phpfile. -
bootstrap/app.php – The request is passed to the app.php, which loads middlewares and configurations.
-
Routing – Laravel matches the URL with the defined route (
routes/web.phporroutes/api.php). -
Controller / Closure – If the route matches, it calls the related controller method.
-
Response – Finally, a response (HTML, JSON, or redirect) is sent back to the user.
Understanding this flow is important because when you debug requests, you’ll know exactly where things happen.
Types of Requests in Laravel
Laravel supports all HTTP request types.
1. GET Request in Laravel
GET requests are mostly used to fetch data or display pages.
In Blade (link example):
In Controller:
2. POST Request in Laravel
POST requests are used when submitting forms.
In Blade Form:
<form action="{{ route('post.store') }}" method="POST"> @csrf
<input type="text" name="title">
<button type="submit">Save</button>
</form>
In Controller:
public function store(Request $request) {
$title = $request->input('title');
return "Post saved: " . $title;
}
3. PUT / PATCH Request
Used for updating data.
Blade:
<form action="{{ url('/post/1') }}" method="POST">
@csrf
@method('PUT') <!-- or PATCH -->
<input type="text" name="title" placeholder="Enter Title">
<textarea name="content" placeholder="Enter Content"></textarea>
<button type="submit">Update Post</button>
</form>
4. DELETE Request
Used for deleting resources.
Blade:
<form action="{{ url('/post/1') }}" method="POST">
@csrf
@method('DELETE')
<button type="submit">Delete Post</button>
</form>
Route:
Route::delete('/post/{id}', [PostController::class, 'destroy']);
Controller:
public function destroy($id)
{
$post = Post::findOrFail($id);
$post->delete();
return response()->json([
'message' => 'Post deleted successfully'
]);
}
AJAX Request in Laravel
AJAX requests are very common in modern apps. Laravel makes it simple to handle them.
Blade Example (jQuery):
$.ajax({
url: "/posts",
type: "POST",
data: { title: "New Post",
_token: "{{ csrf_token() }}" },
success: function(response) {
alert(response);
}
});
Controller:
public function store(Request $request)
{ if ($request->ajax()) {
return response()->json([ 'message' => 'AJAX request received', 'data' => $request->all() ]);
}}
cURL Request in Laravel
Sometimes you need to send HTTP requests to external APIs. Laravel can handle this easily using cURL or the built-in HTTP Client.
Using Laravel HTTP Client:
use Illuminate\Support\Facades\Http;
$response = Http::get('https://jsonplaceholder.typicode.com/posts/1');
$data = $response->json();
return $data;
This is much simpler than writing raw cURL code.
Laravel Custom Validation in Form Request
Validation is very important in requests. Instead of writing validation inside every controller, Laravel provides Form Request classes.
Step 1: Create Form Request
php artisan make:request StorePostRequest
Step 2: Add rules
Step 3: Use in Controller
public function store(StorePostRequest $request) {
return "Post Created Successfully!";
}
This way, validation logic stays clean and reusable.
Laravel Get Request in Blade
You can also send query strings directly from Blade.
<a href="{{ route('post.index', ['page' => 2]) }}">Next Page</a>
Laravel Get Request Parameters in Controller
When you send query strings like ?id=5&name=ahmad, you can access them:
public function show(Request $request) {
$id = $request->query('id');
$name = $request->query('name');
return "ID: $id, Name: $name";
}
Useful Request Methods in Laravel
$request->all() |
Get all input data |
$request->input('key') |
Get single input |
$request->only(['key1','key2']) |
Get specific inputs |
$request->except(['password']) |
Exclude specific inputs |
$request->method() |
Request method |
$request->isMethod('post') |
Check request type |
$request->ip() |
Get client IP |
$request->header('User-Agent') |
Get header info |
$request->ajax() |
Check if request is AJAX |
Best Practices for Laravel Requests
- Always validate input before using it.
- Use Form Requests for clean code.
- Protect forms with @csrf token.
- Use Laravel HTTP Client instead of raw cURL.
- Keep business logic in services, not controllers.
Conclusion
Requests in Laravel are the foundation of how your application works. From the request lifecycle to form submissions, AJAX requests, and cURL requests, everything revolves around handling data coming from the client.
By using the right methods, custom validation, and Laravel’s built-in helpers, you can handle requests securely and efficiently.
Whether you’re building a small blog or a big enterprise app, understanding request in Laravel will make your development journey much smoother.