Laravel Community Tools by Tighten

Tag "blade" tricks

45 tricks
For one of my projects I needed to get an ID of the previous and next record in the DB. This could go well with portfolios, orders, blog posts, all kinds of things where you need to display next/previous entry links. Let’s say we are logged in as an admin and we are on this user’s page and we want to see next/previous user’s id. The following Eloquent code makes it easy to do that. Enjoy!
msurguy 12 years ago 17431
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148885
Sometimes you want to render a partial without sharing all the scope. I often found that the scope inheritance between highly decoupled UI modules makes hard to find errors, because we end up using similar variable names in each module (using @include) Let me show you an example:
fedeisas 12 years ago 10484
Previously, if you wanted to output a default value of a string in Blade you would put a condition that checks if the variable is set, otherwise defaults to some value. Now you can shorten the code by using the keyword "or" to specify what should be displayed if the variable is not set.
msurguy 12 years ago 11482
If you find out, that your blade template is empty and no error message generated: double check your comments
mring 12 years ago 8616
This trick is handy for wrapping all of your form elements with the same HTML/classes, which is especially useful for handling error states when using frameworks like Bootstrap or Foundation.
crhayes 12 years ago 12602
When you need to pass more attributes to a form element using blade syntax.
ramirors 12 years ago 25103
Did you know that Laravel comes with a great amount of helpers to generate HTML in your Blade templates, like UL and OL lists, obfuscating email links, links to javascript and style assets? Check out the code below to see the HTML helpers in action.
msurguy 12 years ago 37710
Usually you would use @section and @stop to pass data to a Blade section. When your data is limited to a short text like page title you could use the second argument of @section to pass that data.
msurguy 12 years ago 8166