Using the code from this question,
@extends('layouts.' . isset($ajax) ? 'ajax' : 'master')
to check for Ajax. It works for regular Ajax page loads but not when using a popup.
In this case I'm using Magnific Popup's Ajax mode, the request header is XMLHttpRequest but Laravel returns the non-ajax (extended) layout.
First of all I don't know how the
$ajax
variable is being set(isset($ajax)
), but the right way to check for an ajax request inLaravel
isOr, short form (using ternary operator in a single expression)
So, according to your link of another answer, this should work
How this works ?
In
vendor\laravel\framework\src\Illuminate\Http
there is aRequest.php
class you can seeHere
isXmlHttpRequest()
is an extended method fromRequest.php
class ofSymphony
, becauseLaravel
'sRequest
class extendsSymfony\Component\HttpFoundation\Request.php
and in this class there is the main method which determines theajax
request bySo, if
X-Requested-With
request header is set then it's an ajax request and if this header is not sent then it's not anajax
request. So, the question is howisset($ajax)
is being set and if it's set by you then thejQuery
library you are using it is not doing it but it's sendingX-Requested-With
request header instead and in this case you should useLaravel
'sRequest::ajax()
method to determine theajax
request.BTW, I would prefer to use a completely different
view
forajax
request which doesn't extendmaster
layout. You may like this Detect Ajax Request-Php And Frameworks.