How to Check Request Method is GET or POST in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check If Request Has File in Laravel?
- How to Update Multiple Records in Laravel?
- How to Store Array in Database Laravel?
- FCM Push Notification in Laravel Example
- Laravel Ajax CRUD with Popup Modal Example
- How to Automatically Generate Sitemap in Laravel?
- How to Add Password Protection for PDF File in Laravel?
- Laravel Generate Unique Slug Example
- Laravel Eloquent firstWhere() Example
- Laravel Eloquent withSum() and withCount() Example
- How to Generate BarCode in Laravel?
- Laravel Signature Pad Example Tutorial
- How to Check Request is Ajax or Not in Laravel?