Should work is the variable set?
!= or <> does not work in @if
When I use
@if($variable <> 0) text @endif
or
@if($variable != 0) text @endif
In blade file it does not work , other comparisions work perfectly. You know anything about that?
dump out variable just before this line..
Only the second form is valid
or
@if(!$variable == 0) text @endif
Yes it would help to know what the variable is.
If still in a string format
@if($variable <> '0') text @endif
Should definitely work. If the variable is set that is.
But I am referring to PHP I have no idea about blade.
Blade statements are php, D'oh !
I never use <> in a php context but it is valid
$a != $b Not equal TRUE if $a is not equal to $b after type juggling.
$a <> $b Not equal TRUE if $a is not equal to $b after type juggling.
... after type juggling. Quoting 0 makes no difference
I just did this:
public function testVar()
{
$variable = 1;
if ($variable <> 0){
echo 'I ain\'t zero';
}
}
When ran I got
I ain't zero
So that's telling me something is going on in blade that isn't working right.
OP, try stright php in the view just to see if it works, we do not know where that variable came from.
I will try it in blade, I don't use blade so will take a few minutes.
@kordix to inform you
@if($variable <> 0) text @endif
does work in blade, I just:
public function testVar()
{
$variable = 1;
if ($variable <> 0){
echo 'I ain\'t zero';
}
return view('dog.test')->with('variable', $variable);
}
And in view:
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
@if($variable <> 0)
not zero
@endif
</div>
</body>
</html>
And I got:
not zero
As expected.
I had to dig into docs to do that, I don't use blade, except for custom pagination templates.
Some php pdo drivers for mysql (could be other engines as well?) return numbers as strings. That could be what's happening.
The mysqlnd driver returns data as-is, which is preferable imo.
What are you on buddy?
Why don't you just wait for the OP to reply rather than keep reinforcing that you don't know what blade actually does.
This
<?php $variable=1 ?>
@if($variable != 0) text @endif
Compiles in the view to
<?php $variable=1 ?>
<?php if($variable != 0): ?> text <?php endif; ?>
You see.... PHP
Now, perhaps if the OP is actually putting this code in an area of the page that is not actually displayed.....
@snapey because you said earlier
Only the second form is valid
So I was testing I did not think they had taken the first form out of PHP.
The point being
<>
Is good. And asking what I'm on, well it's a two way street, you were the one who said the quote above. So that made me curious. Maybe both of us should wait.
I swear on God
dd($drzwi->wizjer)
shows "S"
@if($drzwi->wizjer <> 0) Wizjer @endif
does not show anything. This works:
@if($drzwi->kontaktron == 1)Kontaktron @endif
just I swear on God next to it in the same place same with !=
EDIT holu shit the quotes ("0") worked
It's good the quotes made it
Please or to participate in this conversation.