Blade tip: @unless instead of @if-statement

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:

It works and it’s ok to write it but Laravel has a way better solution:

Another example – let’s say we have to show our posts, unless there are no posts:

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.

Liked the article? Maybe you need help with your Laravel project?
Our LaravelDaily Team can help!

One thought on “Blade tip: @unless instead of @if-statement

Leave a Reply

Your email address will not be published. Required fields are marked *