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 - Available 4 Laravel gigs
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.
👉A #Laravel DB Cheatsheet Part 1/5 🔥🔥 #PHP
🎉Part 2 coming tomorrow 👀
💡 #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).
🔥 #Laravel Tip: Here’s a simple, but important one… particularly if you’re new to the framework. Make sure that aggregations are done within the DB and not Laravel. Go even further with indexes and WHERE constraints: