In this tutorials we will share with you how to check request is ajax or not in laravel. some time we work with laravel API then it is help more. because help of this you can manage you API ajax request and web request in same controller so, you can manage you code very easy way.
You can check ajax request help of ajax() function in laravel.
Laravel Request class has many method to read HTTP request from the currenct request. ajax() one of them
public function index(Request $request)
{
if($request->ajax()){
return response()->json(['status'=>'Ajax request']);
}
return response()->json(['status'=>'Http request']);
}
public function index()
{
if($request->ajax()){
return response()->json(['status'=>'Ajax request']);
}
return response()->json(['status'=>'Http request']);
}
We hope these small tutorials help everyone. if you like this article then please comment below. Thanks..
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Two way Data Binding in Angular 12
When you create a variable or property t...How to Remove Duplicate Values from an Array in PHP
In this article, i will share with you h...Python String Splitlines Method
Python splitlines() is an inbuilt method...Laravel 5.5 - The page has expired due to inactivity - issue
Today, we are share with you how to reso...Laravel Eloquent One to One Polymorphic Relationship Tutorial with Example
While designing database structure, you...