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,288 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,840 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,840 points
6,712 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,840 points
6,250 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,840 points
4,002 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,840 points
1,680 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, 2020 in Laravel by Niroj
• 82,840 points
1,441 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, 2020 in Laravel by Niroj
• 82,840 points
1,014 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, 2020 in Laravel by Niroj
• 82,840 points
2,416 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, 2020 in Laravel by Niroj
• 82,840 points
13,126 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, 2020 in Laravel by Niroj
• 82,840 points
17,034 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP