Laravel Community Tools by Tighten

Tag "database" tricks

87 tricks
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 25379
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148484
Automatic adding user id. In the: First create columns into database tables with names "updated_by" and "created_by"
fhferreira 12 years ago 17932
It truncates all tables and then it runs all seeders available.
kostaspt 12 years ago 17261
This stumped me for some time and after digging around I found it works great, the uploaded file can be removed from the server as well as the database entry. works well for file sharing and image sharing sites.
blackrain 12 years ago 22501
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 30257
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 11647
Use this to generate a select box from a Eloquent Collection
xLink 12 years ago 11318
In the background create your paginated response however you wish.
clouddueli... 12 years ago 48336