Laravel Pro Tips
🔥 #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’:
🔥 #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…
Laravel tip 💡You can use the 'resolveRouteBinding' method on your model to modify the value that is used to resolve the binding.
😍 You can retrieve date from request in specific format and timezone 🤯
#laravel #laraveltips #laraveltricks #laravelforever
Laravel Updates | Tips and Tricks
🔥 #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.
#Laravel Migration Tip 🔥
You can use the `from` method to set the starting value of an auto-incrementing field.
#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.
🔥 #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.
🔥 #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).