Laravel Community Tools by Tighten

Category "Eloquent" tricks

140 tricks
Combining Model Observers and Cache Tags for very simple but elegant automatic cache flushing on Eloquent Model updates. Can handle both a Model and its Relations easily!
nik-418 12 years ago 30267
Here's a simple little scope that you can use to get a random collection of Model objects from the database.
davidhemph... 12 years ago 11659
Use this to generate a select box from a Eloquent Collection
xLink 12 years ago 11326
When you save the password fields, it's been hashed every time. You have to put it in your User model. Thanks to Karl Merkli to add needsRehash
HakShinKen 12 years ago 9678
4.1
I have a legacy system that uses SHA1 for passwords as opposed to bcrypt, which is used by Laravel. For now, I need people to be able to access through both systems. I use the auth.attempt event to handle password conversion.
madshadow 12 years ago 14921
Use this trick to log queries using Monolog. Add this to your routes.php and log straight into your Firebug console. Firebug needs the FirePHP add-on. - kisses Netbulae
xtrasmal 12 years ago 12671
I have added a sitemap to this very site and was thinking that some of you want to do the same for SEO purposes. The way to add a sitemap would be pretty easy by using a Blade template for the XML that sitemap requires but there is an easier solution. You can use a package from https://github.com/RoumenDamianoff/laravel4-sitemap that would make it super simple to generate a sitemap for your Laravel application. See for yourself.
msurguy 12 years ago 35229
I spent a good hour trying to figure out why my Eloquent relationship wasn't working when I found out it was because of the difference between `$model->relationship->value` and `$model->relationship()->value`.
chadwithuh... 12 years ago 109834
I have put together a custom collection that will allow you to access a relationship on all objects in a collection. You can also run a method from an object in the collection on the entire collection such has touch or delete.
riddles888... 12 years ago 32242
4.0