Laravel Pro Tips
🔥 #Laravel Tip: Eloquent's 'whereExists' method is useful, but it relies on sub queries. A more efficient way to run the same query is an advanced inner join.
🔥 Laravel Tip: Auto-completion in artisan commands.
When you prompt a user for input, you can use the `anticipate` method to auto-complete possible responses.
🔥 #Laravel Tip: Seeding your database one record at a time can slow the DB to a halt. A better option is to use PHP to make a bunch of records and then seed them in chunks. Here’s how you can go from 10,000 queries to 5!
🔥 #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.