Laravel Pro Tips
🔥 #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.
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.
🔥 #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:
When eager loading relationships in Laravel, you can specify the columns you need directly in the `with` method 🍃
🌶️ #Laravel Tip: Cleaning up the Controller is a responsibility!
I find myself moving things out of the Controller to FormRequest, Action, Services, etc.
Here's how you can authorize a request inside the FormRequest & not in the Controller Action.
Bilal Haidar - Available 4 Laravel gigs
👉A #Laravel Lang (Translation) #Cheatsheet #PHP
Aaron Lumsden 🎉 | Indie Hacker Dev
Laravel Tip 💡 Did you know you can enrich request data using a middleware? For example, resolve the user origin country using their IP and add the country abbreviation to the request.
Laravel Tip: If we want to put "sensitive" data in our DB then we can use Crypt Facade and handle these using accessors and mutators.
An efficient way of checking if a relation exists in Laravel is to use withExists.
It performs a simple existence check and returns a boolean.
By default it would return a "posts_exists" value on the User.
You may alias it like in the example below to make it more readable.