Laravel check if Ajax request Example

Today, We want to share with you Laravel check if Ajax request Example.In this post we will show you How to check if a Request is an AJAX call with PHP, hear for Laravel 5.8 return JSON or View depends if ajax or not we will give you demo and example for implement.In this post, we will learn about How to check request is Ajax or not in Laravel 5? with an example.

Laravel check if Ajax request Example

There are the Following The simple About PHP check if Ajax request Example Full Information With Example and source code.

Also Read :  Create Dynamic Web Pages using PHP-MYSQL

As I will cover this Post with live Working example to develop Laravel 5.8 testing route protected by $request->ajax(), how to make test ajax request?, so the some major files and Directory structures for this example is following below.

Example 1: How to Detect Ajax Request in Laravel

public function index(Request $request)
{
    if($request->ajax()){
        return response()->json(['ajax']);
    }
    return response()->json(['http']);
}

Example 2: Laravel Request::ajax()

public function index()
{
    if(Request::ajax()){
        return response()->json(['ajax']);
    }
    return response()->json(['http']);
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP check if Ajax request.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Also Read :  Shorthand comparisons using PHP Ternary Operator

Leave a Reply

avatar
  Subscribe  
Notify of