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? We not only write, we also create useful tools!
Have you seen our tool to generate Laravel adminpanel online?
You don't need any packages to do that!

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

Leave a Reply

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