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)
Share:
104,740

Related videos on Youtube

toesslab
Author by

toesslab

Updated on July 09, 2022

Comments

  • toesslab
    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
      Markus Kottländer over 10 years
      Have you tried out your code and it doesn't work?
    • ThiefMaster
      ThiefMaster over 10 years
      PHP does not have a 4-equals operator. Did you mean ===?
    • toesslab
      toesslab over 10 years
      Sry typo with ====. To be clear. a simple @if is working perfectly, so it's not the condition itself
  • toesslab
    toesslab over 10 years
    I tested it before coming in here, but you're right. The problem must be elsewhere...
  • Unnawut
    Unnawut almost 10 years
    @pc-shooter so what is the actual problem? Any error message?
  • prudhvi259
    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