Laravel Pro Tips
💡#Laravel Eloquent Tip
Laravel 8 introduced the Prunable trait. You can use it to delete old models on a scheduled basis.
You don't need to write custom commands anymore:
🔥 Epic Laravel Tip: Did you know that you can generate not only text values but also images with Faker?
Marian Pop 🇺🇦 Laravel Magazine
🕵️♂️ In your Laravel apps, you might want to detect if a request has been made by a bot or crawler.
It's super simple to do using the "jenssegers/agent" package.
Ash Allen 🚀
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! 💅🤩
Steve Bauman 💎
🔥 #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.
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