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... 5 years ago 13301
This query searches the data from the Table and also with its relation table columns dynamically.
Muzamil-kh... 5 years ago 10612
Get products count which are under sub categories of a parent category
Faridbabay... 5 years ago 12001
set custom table name for eloquent model
uniqueginu... 5 years ago 8346
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 16270
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 17991
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 15404
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 15632
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 25085