How to check request is Ajax or not in Laravel?

How to check request is Ajax or not in Laravel?

In this post we will give you information about How to check request is Ajax or not in Laravel?. Hear we will give you detail about How to check request is Ajax or not in Laravel?And how to use it also give you demo for it if it is necessary.

Sometimes, we need to check request is ajax or not in laravel 5. If you want to call same method but if request is ajax then you perform different, then you can do by using $request object.

In Laravel 5 $request object provide method to check request is ajax or not, In following example you can see how it’s works.

You can check directly from Request facade and also from request object, both are same, so let’s see bellow example.

Example 1:

public function index(Request $request)

{

if($request->ajax()){

return response()->json(['ajax']);

}

return response()->json(['http']);

}

Example 2:

Also see:Laravel – How to get current URL in controller or view?

public function index()

{

if(Request::ajax()){

return response()->json(['ajax']);

}

return response()->json(['http']);

}

Hope this code and post will helped you for implement How to check request is Ajax or not in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  52  =  58

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US