Looking for a ternary operator for blade templates
@if(Auth::check()) ? yes : no @endif
Can't seem to get it to work this works
@if(Auth::check()) yes @else no @endif
suppose there is not much in it for this example, just curious.
The ternary operator is a conditional operator that decreases the length of code while performing comparisons and conditionals. This method is an alternative for using if-else and nested if-else statements.
The term "ternary operator" refers to an operator that operates on three operands. An operand is a concept that refers to the parts of an expression that it needs. The ternary operator in PHP is the only one that needs three operands: a condition, a true result, and a false result.
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
You are free to use it with {{ }}
.
{{ Auth::check() ? 'yes' : 'no' }}
This works:
{{ Auth::check() ? 'yes' : 'no' }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With