Laravel Pro Tips
👉A #Laravel Lang (Translation) #Cheatsheet #PHP
Aaron Lumsden 🎉 | Indie Hacker Dev
🌶️ #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 | Laravel Enthusiast
When eager loading relationships in Laravel, you can specify the columns you need directly in the `with` method 🍃
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.
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.
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.
💡 #Laravel Tips of the day 😎
𝗗𝗼𝗻’𝘁 𝗙𝗶𝗹𝘁𝗲𝗿 𝗯𝘆 𝗡𝗨𝗟𝗟 𝗶𝗻 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀: We can filter by NULL in Eloquent, but if we're filtering the collection further - filter by empty string, there's no "null" in that field anymore. #php #backend
🔥 #Laravel Tip: Make use of ‘orderByRaw’ when you need to sort records in a more complex manner than simply A-Z or Z-A. Here’s an example where I sort ‘roles’ based on their level of importance (rather than their alphabetical order).
Matt Kingshott 🏝
👉A #Laravel DB Cheatsheet Part 1/5 🔥🔥 #PHP
🎉Part 2 coming tomorrow 👀