How to check request is ajax or not in Laravel?

0 votes
I Want to know how can we consider if the request send by the user is ajax request or not in laravel?

Thank you!!
Mar 23 in Laravel by kartik
• 10,760 points
51 views

1 answer to this question.

0 votes

Hello,

Laravel allow use of their library method that can be use to identify the request is ajax or not.

In Laravel, we can use $request->ajax() method to check request is ajax or not.

Example:

      public function saveData(Request $request)
        {
            if($request->ajax()){
                return "Request is of Ajax Type";
            }
            return "Request is of Http type";
        }

Thank you!!

answered Mar 23 by Niroj
• 21,680 points

Related Questions In Laravel

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
96 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
• 21,680 points
58 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
• 21,680 points
145 views
0 votes
1 answer

How to check if a record already exists in a laravel?

Hey, As a newbie it is most common ...READ MORE

answered Mar 31 in Laravel by Niroj
• 21,680 points
243 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 21,680 points
394 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 21,680 points
58 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 21,680 points
63 views
0 votes
1 answer

What are named routes in Laravel?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 21,680 points
128 views
0 votes
1 answer

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

Hey, In order to identify the type of ...READ MORE

answered Mar 19 in Laravel by Niroj
• 21,680 points
38 views
0 votes
1 answer

How to load blade or php content into a view via ajax/jquery in laravel?

Hello @kartik, Assuming you're using jQuery... create a route ...READ MORE

answered Apr 14 in Laravel by Niroj
• 21,680 points
226 views