Laravel Pro Tips
#eloquent #indexes
🔥 #Laravel Tip: Eloquent’s ‘whereDate’ function is useful, but it prevents the database from using an index, which can effect performance on large tables. Fortunately, it is easy to replace it with ‘whereBetween’:
Matt Kingshott
#eloquent #refactor
🔥 #Laravel Tip: Eloquent provides a ‘withCount’ method, but it uses a sub-query, which can be up to 8 times slower (or more in some cases) than using a leftJoin & groupBy. Refactoring only requires a few changes and can make a big difference…
#routes #models
Laravel tip 💡You can use the 'resolveRouteBinding' method on your model to modify the value that is used to resolve the binding.
Philo Hermans
#requests #dates #timezones
😍 You can retrieve date from request in specific format and timezone 🤯 #laravel #laraveltips #laraveltricks #laravelforever
Laravel Updates | Tips and Tricks
#eloquent #relationships
🔥 #Laravel Tip: Eloquent offers many undocumented methods that can help to make your code easier to read. For example, the whereBelongsTo method simplifies finding resources that belong to a model instance.
#migrations
#Laravel Migration Tip 🔥 You can use the `from` method to set the starting value of an auto-incrementing field.
Gurmandeep Singh
#validation #closure
#Laravel Validation Tip 🔥 You can use a closure instead of a rule object if you only need a custom rule once throughout your application. The closure receives the attribute's name, the attribute's value, and a `fail` callback that should be called if validation fails.
#validation #error #ux
🔥 #Laravel Tip: Using custom error messages for failed request validation is straight out of the docs, but it’s amazing how rarely it gets used. Make your apps better and improve their UX by giving users more guidance in solving validation errors.
#macros #query builder
🔥 #Laravel Tip: Macros provide a way to add missing functionality to many parts of the framework, such as the query builder. These macros can be "user-facing", but they don't have to be. Sometimes they can be used just to make your tests simpler (or to aid in debugging).