Laravel Pro Tips
#Laravel #Database Tip:
On v9.18 you can get notified when the application spends too much time querying the database during a single request. Add `whenQueryingForLongerThan` closure in the boot method of `AppServiceProvider`.
#Laravel #Database #PHP
💡 #Laravel Tips of the day 😎
Laravel 𝘀𝗸𝗶𝗽 𝗺𝗲𝘁𝗵𝗼𝗱 𝗶𝗻 𝘀𝗰𝗵𝗲𝗱𝘂𝗹𝗲𝗿 - We can use skip in your commands to skip an execution. #php #backend
🔥 If you've ever found yourself manually dealing with request inputs looking to parse it to Carbon. You might want to use the `date` method on the Request instance instead. #Laravel #PHP
Morten Poul Jensen
Laravel Tip 💡 v9.16 introduces a new withWhereHas() to reduce code duplication 💅 Time to do a bit of cleaning 🧹
#Laravel Tip 🔥 : You can set the prefix in array keys with newly released method prependKeysWith() in Laravel 9.14.0
Let's checkout an example 👇:
#PHP #webdevelopers #100DaysOfCode #developers
Mohammad Haris ⚡
💡 Quick #Laravel Eloquent tip for comparing database columns to each other within a query.
You don't have to use any raw statements to do this - whereColumn() has got you covered! 😊
Lupinity Labs | Freelance Software Dev
🔥 #Laravel Tip: If you need to render dates and times a lot in your app, then consider making a custom Carbon class. You can then tell Laravel to always use your class via the Date facade.
Matt Kingshott 🏝
🔥 #Laravel Tip: At scale, calculating metrics for dashboards can take a long time, as you might have to count thousands or even millions of records. Fortunately, you can easily fix this by using model events to maintain stats. Here’s a simple example:
Shoutout to my favorite array helper in Laravel 🔀 Arr::random returns one or multiple random values from an array. Unlike the native array_rand which return a random key.