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, 2020 in Laravel by kartik
• 37,520 points
3,905 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, 2020 by Niroj
• 82,800 points

Related Questions In Laravel

0 votes
1 answer

How to get the id when you're validating in the model Validation unique on update using laravel?

Hello @kartik, in Laravel's inbuilt auth system, the ...READ MORE

answered Sep 11, 2020 in Laravel by Niroj
• 82,800 points
7,261 views
0 votes
1 answer

How to get the subdomain in a subdomain-route in laravel?

Hello, $subdomain is injected in the actual Route callback, it is ...READ MORE

answered Nov 2, 2020 in Laravel by Niroj
• 82,800 points
6,930 views
0 votes
1 answer

How to Get the Current URL Inside @if Statement in Laravel?

Hello @kartik, You can use: Request::url() to obtain the current ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,800 points
4,659 views
0 votes
1 answer
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, 2020 in Laravel by Niroj
• 82,800 points
2,211 views
0 votes
1 answer

How to download and install Lavavel framework?

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