Laravel Community Tools by Tighten

Category "Eloquent" tricks

140 tricks
If you're not making use of MySQL InnoDB cascades, you might still want to cause events (such as deleting) on related models to cascade. The example below listens for the deleted event on the Product model and cascades this to the child models.
robjmills 12 years ago 34893
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 23807
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 125703
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 16398
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 17766