Laravel Community Tools by Tighten

Category "Eloquent" tricks

140 tricks
It's possible to add condition to your model's relationships... Help me to use Eloquent with a legacy database..
Matt 12 years ago 9053
With database seeding you can fill your database with dummy data with simple command. I created code that will fill users table with some data. users table consists of three columns (username,email,biog).
Clivern 12 years ago 58095
For one of my projects I needed to get an ID of the previous and next record in the DB. This could go well with portfolios, orders, blog posts, all kinds of things where you need to display next/previous entry links. Let’s say we are logged in as an admin and we are on this user’s page and we want to see next/previous user’s id. The following Eloquent code makes it easy to do that. Enjoy!
msurguy 12 years ago 17127
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 8475
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 25440
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148532
We have released the source code of this website! You can check out the repository containing a mirror copy of this website: https://github.com/CodepadME/laravel-tricks to create your own websites like Laravel-tricks. It uses PSR-2 coding standards, a ton of libraries and packages and is a good resource to take a look into.
msurguy 12 years ago 9654
Automatic adding user id. In the: First create columns into database tables with names "updated_by" and "created_by"
fhferreira 12 years ago 17961
When saving/updating a model you might want to get a JSON response that includes some relationship data as well.
m4nuC 12 years ago 11149