Skip to main content
Tutorial Free

Blade tip: @unless instead of @if-statement

March 10, 2016
1 min read
Another quick tip for you guys from Laravel world - this time it's about Blade template engine. We have all been in a situation where we had to write something like this:
@if (!Auth::check())
    Please log in.
@endif
It works and it's ok to write it but Laravel has a way better solution:
@unless (Auth::check())
    You are not signed in.
@endunless
Another example - let's say we have to show our posts, unless there are no posts:
@unless(count($posts) == 0)
    
{{ $post->title }}
@endunless
The command @unless checks if our expression returns FALSE - then shows the following data. If the expression returns TRUE - it will ignore the inner part.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

[NEW] Next.js Basics for Laravel Developers

11 lessons
58 min

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min

NativePHP v3: Create Mobile Apps with Laravel

10 lessons
1 h 02 min

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.