Laravel Community Tools by Tighten

Tag "eloquent" tricks

24 tricks
maybe this is a nice way to prevent an eloquent model field being updated with mutators like this:
Tefoh 6 years ago 8636
If you want to count the number of results from a relationship without actually loading them you may use the "withCount" method, which will place a "{relation}_count" column on your resulting models.
kupendra 6 years ago 12050
Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:
BenaliDjam... 6 years ago 9628
You might come up with a situation where you want to check if a given Eloquent attribute was changed compared with its original stored value.
laraning 7 years ago 25093
with this trait you can get Enum values of a table /
nimahkh 7 years ago 12622
If you ever wanted to see the SQL query that is being generated when using the Eloquent or the Query Buider, you can simply use to `toSql` method.
wilburpowe... 8 years ago 3660