Laravel check if ajax request or not example

$request->ajax()

Request::ajax()

Example

public function myIndex(Request $request)

{

    if($request->ajax()){

        return response()->json(['status'=>'Request is Ajax']);

    }

    return response()->json(['status'=>'Request is Http']);

}