Check a Request is Ajax Request or Not in Laravel

How to check a request is ajax or not in Laravel is the todays topic. In this tutorial i will show you how to check from controller that a request is ajax request or not. Sometimes we need to check our request. If you fetch data from controller without checking ajax request, then your data will be insecured. 

So making our data secured you can see the below code of if is ajax request laravel.

Example code :

some controller

if($request->ajax()){
  //success ajax request
}else{
    abort(404)
}

 

Recommended : Laravel withCount() Eager Loading Query Example

 

Hope it can help you.