Press "Enter" to skip to content

Blade Templates – These are useful now.

Sharing is caring!

Ever since laravel now offered Route::view method, several blade directives that were good enough to use became more useful. We do not have to bother the controller anymore. In any case, these blade directives come in handy.

To check if a view exists we can use includeif directive. This way, we won’t end up with a “view not found” error. For me, it becomes most useful when there is some default theme assigned. Because of this, I can create a file or delete them without changing a line of code.

The dirty trick I pull with this directive is for my designer friends. I provide them ftp access to this specific folder whose views(mostly stylesheets) are included using @includeif directive. I ask them to write a stylesheet that belongs to their respective views.. – Don’t do it.

Imagine you have a collection of products and some of them are on the sale. Then @includeWhe directive is to be used.

If you have WordPress, you know this one is handy too. We can have our own (blade) template hierarchy over here.

For iterating, rather than @foreach directive,

Needless to say, laravel views are getting more cleaner and leaner.

Everything is awesome.