Laravel Pro Tips
Checkboxes are a pain to validate against because if they’re not checked they’re not present in the HTTP request. You can solve this by using a hidden input, but #Laravel makes it easy to set up a default in the Request. Now `$request->opt_in` is always true or false. #PHP #Code
🔥 #Laravel Tip: Sometimes you need to seed a database with millions of records e.g. for stress-testing. To avoid crippling the DB with millions of ‘create’ queries, instead consider ‘making’ a large collection of models, then chunk and insert them.
Matt Kingshott 🏝
👉#laravel Request URL Cheat Sheet. 🔥
Aaron Lumsden 🎉 | Indie Hacker Dev
#Laravel Tip 🔥
You can use 'inRandomOrder' method to sort the results of models randomly.
🔥 Laravel Tip: You can specify what to do if a scheduled task fails or succeeds.
Laravel Tip💡You can hide your auto-incremented database IDs from your users by hashing the ID using a library like HashId🕵️
Carbon provides next() and previous() functions that return upcoming and previous occurrences of a particular weekday or time.
Laravel Tip 💡 Add a 'before()' method to your policy to validate a global condition before checking the actual policy permission. Useful when working with multiple guards and/or roles, for example.
#Laravel #Eloquent Tip:
Laravel v9.7 shapes with `whereJsonContainsKey()` method to allow you to check for array integer keys. See the below example.
#Laravel #Database #PHP