How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

0 votes
I want to identify the request i made is get or post and according to that i have to display certain condition. How can i do that?
Mar 19 in Laravel by kartik
• 27,360 points
93 views

1 answer to this question.

0 votes

Hey,

In order to identify the type of HTTP request we use method() function and then check it by isMethod() function to identify the request.

For example: In controller created in Laravel

class user extend controller

{

    public function index(Request $req)

    {

         echo $req->method();

     } 

}

The above code will display the type of request. Now in order to execute certain condition based on request do follow the sample example

class user extend controller

{

    public function index(Request $req)

    {

         echo $req->method();

         if($req->isMethod('GET'))

             echo "Neeraj";

         else

              echo "edureka";

     } 

}
answered Mar 19 by Niroj
• 58,960 points

Related Questions In Laravel

0 votes
1 answer
0 votes
1 answer

How to delete or clear caching in Laravel?

Hey @kartik, There are many commands to clear ...READ MORE

answered Mar 20 in Laravel by Niroj
• 58,960 points
1,495 views
0 votes
4 answers

How to get user's IP address in Laravel?

Use $clientIP = request()->ip(); READ MORE

answered Sep 21 in Laravel by aakash
• 210 points
5,564 views
0 votes
1 answer

What is database migration and how to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
152 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
175 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
172 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
74 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
97 views
0 votes
1 answer

How to check request is ajax or not in Laravel?

Hello, Laravel allow use of their library method that ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
194 views
0 votes
1 answer

How do I get HTTP Request body content in Laravel?

Hello @kartik, Inside controller inject Request object. So ...READ MORE

answered Aug 11 in Laravel by Niroj
• 58,960 points
185 views