ItSolutionStuff.com

How to Check Request Method is GET or POST in Laravel?

By Hardik Savani November 5, 2023
Laravel

Sometimes we require to get request method is get, post, patch, delete that way we can take action. if need take action on depend on request input method. so you can check using request method so let's see bellow examle:

Example 1: Laravel Check Request Method is POST

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Post;

class PostController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function store(Request $request)

{

if ($request->isMethod('post')) {

dd('is post method');

}

}

}

Example 2: Laravel Check Request Method is GET

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Post;

class PostController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function store(Request $request)

{

if ($request->isMethod('get')) {

dd('is get method');

}

}

}

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube