Laravel Pro Tips
When eager loading relationships in Laravel, you can specify the columns you need directly in the `with` method ✨
Just learned about the Eloquent "value()" method from @amaelftah 💪. Eloquent make things so easy. Seems like there's shortcuts hiding everywhere, I love it! 💅🤩
🔥 #Laravel Tip: When you want to send the user a file that their browser natively supports e.g. an image or a PDF, send them a file response instead of a download. That way, the browser will display it for them.
Matt Kingshott 🏝
The @.production blade directive makes it super easy to load e.g. Google Analytics or other stuff when your Laravel app is in production mode
If you're creating custom exceptions inside your Laravel application, you can add a "context()" method to provide additional data to be printed in the log, as well as a "render()" method to allow the exception to display its own view to the user. Super cool! 🤩
In Laravel, there may be times when you need to check if a model was fetched from the database or just created in the current request lifecycle - like when using firstOrCreate().
To do this, you can use the ->wasRecentlyCreated field on the model
Use withCount in Laravel when you want the number of related models for a given relationship without actually loading the models
My 1st Laravel tip in here.
Speed up your Seeders
⚡ ️You can filter Laravel Collections by a given class type using the whereInstanceOf method. You can filter by one particular type or by multiple at once.