When I make request from Postman application to a Laravel Application, the
$request->ajax() is not returning TRUE.
I'm also sending the Accept: application/json header in Postman, Still no luck.
Postman Request Screenshot:
Code Screenshot
When I make request from Postman application to a Laravel Application, the
$request->ajax() is not returning TRUE.
I'm also sending the Accept: application/json header in Postman, Still no luck.
Postman Request Screenshot:
Code Screenshot
Add the header X-Requested-With: XMLHttpRequest
The explanation
If you track down the method ->ajax() it goes through the following function:
/**
* Returns true if the request is a XMLHttpRequest.
*
* It works if your JavaScript library sets an X-Requested-With HTTP header.
* It is known to work with common JavaScript frameworks:
*
* @see https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
*
* @return bool true if the request is an XMLHttpRequest, false otherwise
*/
public function isXmlHttpRequest()
{
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
}
Add the header X-Requested-With: XMLHttpRequest and then $request->ajax() will return TRUE.