use Illuminate\Http\Request; $request = Request::create('/', 'GET', [], [], [], [ 'HTTP_X-Requested-With' => 'XMLHttpRequest' ]); if ($request->isXmlHttpRequest()) { // do something for AJAX requests } else { // do something else for non-AJAX requests }
public function myController(Request $request) { if ($request->isXmlHttpRequest()) { // do something for AJAX requests } else { // do something else for non-AJAX requests } }This method is a part of the Illuminate/Http package, which is a part of the Laravel framework. The package provides classes for handling HTTP requests and responses in your PHP applications.