Laravel Community Tools by Tighten

Tag "4.1" tricks

72 tricks
If you're like me, you don't like to keep repetitive ->where()'s in your routes file, this is where route patterns come in handy. Makes your routes file DRY too, especially when you'll need to change some expression.
vlakarados 12 years ago 51163
Sometimes you would like to restrict a certain route parameter. For instance, if you are using route parameters to determine the ID of a certain model you are using, you would only like digits to be passed, not alphabetical characters. You can set these restrictions on the route using ->where('<pattern>'). But what if you have a huge list of routes that all use the same pattern restriction? That's where this will come in handy.
stidges 12 years ago 12137
This is specific to using Redis for caching. You can group your keys in sections to allow for easily clearing the cache on just a section of data. Couple notes: 1. You have to have 'cluster' set to false in app/config/database.php under the 'redis' key. 2. Remember to pass through variables into the closure with 'use'. 3. Have fun!
gerob 12 years ago 14206
Perform CSRF filter on all post, put, patch, and delete requests through constructor of the BaseController.
mhanson01 12 years ago 18281
When doing some sort of filtering in Eloquent, sometimes you need to use operators other than "=" and there is no easy way to know which operators you can use. This trick details the possible operators for you.
msurguy 12 years ago 23791
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 37363
Put this in your routes.php file and you will see the SQL that Eloquent is executing when you go to pages that have any sort of access to Eloquent models. This helps a lot when debugging SQL in Laravel.
msurguy 12 years ago 125658
I like namespacing my controllers. I think it cleans up my structure a bit, and prevents me from having to 'composer dump-autoload' everytime I make a new controller. Though it is very convenient to namespace your controllers, your routes file can quickly become very messy. Luckily, Laravel 4.1 offers a great solution for this, namely the 'namespace' option in Route::group().
stidges 12 years ago 73675
4.1
Ever find yourself wanting to only find models that have a certain relationship matching certain conditions? Laravel 4.1 makes this really easy, and introduces great eager loading constraints!
stidges 12 years ago 17744