JoaquinVilchez's avatar

Blade - Conditional does not work with internal parentheses.

Hello I want to make an alert appear on all pages except some and only if the cart is not empty ...

@if(!\Cart::isEmpty() && (Request::path()!='checkout' || Request::path()!='login' || Request::path()!='register'))
            <div class="alert alert-warning mb-0 text-center" role="alert">
                Tienes un pedido pendiente. <a href="{{route('checkout.index')}}" class="alert-link">Finalizar pedido</a> 
            </div>
@endif

I try to do this but I have no results ... Can Blade do internal parentheses inside a codicional?

Thank you.

0 likes
3 replies
JoaquinVilchez's avatar

No, I tried the @php directives like you told me, and it didn't work ... and I also opened the Tags as if it were a normal html and it also doesn't work ... weird.

If I remove the parentheses and leave the && it only works, but with the internal parentheses it doesn't.

JoaquinVilchez's avatar
JoaquinVilchez
OP
Best Answer
Level 2

I solved it by doing all ANDs, I hadn't really thought of it that way, but I tried and it worked.

@if(!\Cart::isEmpty() and Request::path()!="checkout" and Request::path()!="login" and Request::path()!="register")
<div class="alert alert-warning mb-0 text-center" role="alert">
Tienes un pedido pendiente. <a href="{{route('checkout.index')}}" class="alert-link">Finalizar pedido</a> 
</div>
@endif

Thanks for your time

Please or to participate in this conversation.