Blade view: if statement with OR/AND condition
104,740
Solution 1
It should support all of your standard PHP operators, including || (logical OR).
I have tested it myself and it works fine.
Additionally, I would recommend simply testing this yourself in future to confirm it works/doesn't work.
Solution 2
You can simply use and
/ or
operators:
@if($a==1 and $b==2)
@if($a==1 or $b==2)
Related videos on Youtube
Author by
toesslab
Updated on July 09, 2022Comments
-
toesslab almost 2 years
Is it possible in Laravel 4.0 -blade-view to do an if statment like so?
@if ($var1 === '1' OR $var2 === '1') //Do my stuff @endif
Or
@if ($var1 === '1' || $var2 === '1') //Do my stuff @endif
Or whatever syntax it is. I didn't find anything in the L4 docs, does it exist ?
-
Markus Kottländer over 10 yearsHave you tried out your code and it doesn't work?
-
ThiefMaster over 10 yearsPHP does not have a 4-equals operator. Did you mean
===
? -
toesslab over 10 yearsSry typo with ====. To be clear. a simple @if is working perfectly, so it's not the condition itself
-
-
toesslab over 10 yearsI tested it before coming in here, but you're right. The problem must be elsewhere...
-
Unnawut almost 10 years@pc-shooter so what is the actual problem? Any error message?
-
prudhvi259 almost 7 years
@if(Session::has('user_handle') && Session::get('user_handle') == $angular_to_handle1)
here '&&' not working for me. i am using laravel 5.2