Laravel Community Tools by Tighten

Stidges

Joined: 12 years ago
Total tricks: 7
Last trick: 11 years ago

Submitted tricks

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 17739
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 73660
4.1
Laravel offers a dynamic interface for assigning certain data. This can be used e.g. for adding a dynamic 'where' to your Eloquent queries. However, not everyone know that this same trick also works on View assignments!
stidges 12 years ago 12669
It can sometimes be convenient to automatically validate your model when it gets created or updated. This is very easily achieved with Laravel through the use of Model events.
stidges 12 years ago 16366
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 12131
This function will allow you to forget about cache busting mechanisms. It will use your desired method of cache busting, either <filename>.<buster>.<extension> (default) or <filename>.<extension>?<buster>. You can use this to replace asset() entirely and never worry about updating those pesky cache busters whenever you update a file!
stidges 11 years ago 14323
I recently figured out that you can specify the columns that you want to select from an eager loaded relationship in Eloquent. I thought others might find this useful as I couldn't find much about this online!
stidges 11 years ago 41976