Laravel Community Tools by Tighten

Tag "models" tricks

58 tricks
Sometimes you might want to delete/update a whole lot of items that are related to a model when a record under that model is deleted from the database. This could be useful for various scenarios when there is a lot of processing that needs to be done upon model deletion. Laravel provides model events that you can use in that case.
msurguy 12 years ago 41205
It's possible to add condition to your model's relationships... Help me to use Eloquent with a legacy database..
Matt 12 years ago 9059
logs a sql query with bindings replace by actual values
eugene_san... 12 years ago 9210
If you have datetime fields lets say, last_updated or registered_at, this is a nice trick to make laravel know about that fields & let it know. Just overwrite Eloquent's constants.
kbirmhrjn 12 years ago 8481
Inside my seeders I often use this trick to prevent from re-seeding already present values. For example, if you are creating a base seed of production data -- say a pre-defined list of values -- and add a new item but do not want to delete all seed data and re-seed, you can try this. Note that, there are some flaws to it. Such as: It will not delete missing values if your new list has changed, or if you set the attributes too specific, you may end up creating a duplicate (for instance, if you have the same item with different `order` values due to rearranging in the list).
chadwithuh... 12 years ago 25455
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148541
Automatic adding user id. In the: First create columns into database tables with names "updated_by" and "created_by"
fhferreira 12 years ago 17967
When saving/updating a model you might want to get a JSON response that includes some relationship data as well.
m4nuC 12 years ago 11151
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 30289