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
• 4,560 points
22 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
• 8,620 points

Related Questions In Laravel

0 votes
1 answer

How to get user's IP address in Laravel?

Hey, We can get the user's IP address ...READ MORE

answered Mar 20 in Laravel by Niroj
• 8,620 points
26 views
0 votes
1 answer

How to pass CSRF token with ajax request in Laravel?

Hey, In between head, tag put <meta name="csrf-token" ...READ MORE

answered Mar 24 in Laravel by Dey
31 views
0 votes
1 answer

How to enable or disable maintenance mode in Laravel?

Hii, We have to use the following artisan ...READ MORE

answered Mar 24 in Laravel by Niroj
• 8,620 points
31 views
0 votes
1 answer

How to get distinct values for non-key column fields in Laravel?

Hello @kartik In eloquent you can use this $users ...READ MORE

answered 5 days ago in Laravel by Niroj
• 8,620 points
13 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
• 8,620 points
32 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
• 8,620 points
30 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
• 8,620 points
21 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
• 8,620 points
20 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
• 8,620 points
32 views
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
• 8,620 points
31 views