Laravel Pro Tips
#scheduler #models #prunable
π‘#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:
Martin Joo
#faker #testing
π₯ Epic Laravel Tip: Did you know that you can generate not only text values but also images with Faker?
Marian Pop πΊπ¦ Laravel Magazine
#requests
π΅οΈββοΈ 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. #laravel #php
Ash Allen π
#eloquent #relationships #eager loading
When eager loading relationships in Laravel, you can specify the columns you need directly in the `with` method β¨
Daniel Eckermann
#eloquent
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 π
#downloads #responses
π₯ #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
#blade #directives
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
#exceptions
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! π€©
#eloquent #models
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 #laravel #php