Using the @unless Control Structure in Blade

Problem

You need conditional logic in a Blade template.

You want to output html within the template when a condition is false. Yes, you know you can do @if ( ! condition), but are curious if there's a more elegant way.

Solution

Use the @unless control structure.

@unless ($age >= 18)
    You can't vote.
@endunless

Discussion

Pretty simple.

What Blade does internally is change your @unless(condition) into a if ( ! condition).

comments powered by Disqus