Laravel Community Tools by Tighten

Category "Eloquent" tricks

140 tricks
Save yourself from all the boilerplate of tracking/observing and reacting to model attribute changes.
alexstewar... 4 years ago 13011
This query searches the data from the Table and also with its relation table columns dynamically.
Muzamil-kh... 4 years ago 10246
Get products count which are under sub categories of a parent category
Faridbabay... 4 years ago 11563
set custom table name for eloquent model
uniqueginu... 5 years ago 8037
Using laravel eloquent, you have an amazing feature called `Accessors`, which allows you to define a non-existing column, here's an example to get user full_name that does not exist in the users table
thefeqy 5 years ago 15929
If you have DB column which you want to be set only once and never updated again, you can set that restriction on Eloquent Model, with a mutator
fatihtopra... 5 years ago 17737
What if you’re working with non-Laravel database and your timestamp columns are named differently? Maybe, you have create_time and update_time. Luckily, you can specify them in the model, too
fatihtopra... 5 years ago 15120
You can filter by NULL in Eloquent, but if you're filtering the collection further - filter by empty string, there's no "null" in that field anymore.
fatihtopra... 5 years ago 15348
You can unguard all your Models instead of setting the protected guarded variable to an empty array in each App\Models\YourModel class using Model::unguard() in the boot method of AppServiceProvider class.
berto309 5 years ago 24566