David Tunnell
David Tunnell

Reputation: 7532

Using variable from controller in an if statement

I have a variable that is passed from the controller. It works fine when I just have it rendered as HTML however I am trying to use it in a PHP if statement and in this case it is saying that it doesn't exist.

@if ([[private_count]] != 0)
     <div>Content</div>
@endif

I think it has to do with calling the [[]] shorthand within PHP but how else would I be able to use it to compare?

Upvotes: 1

Views: 1095

Answers (2)

tommy
tommy

Reputation: 3615

Blades @if directive is just a wrapper around PHPs native if:

@if($private_count != 0)
    <div>Content</div>
@endif

Upvotes: 4

Scarecrow
Scarecrow

Reputation: 4137

you can use simple php code also.

 <?php if(condition ){ ... }?>

It also works with .blade template

Upvotes: 3

Related Questions