Laravel Pro Tips
#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
Daniel Eckermann
#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! ๐คฉ
Steve Bauman ๐
#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
Ash Allen ๐
#eloquent #relationships #performance
Use withCount in Laravel when you want the number of related models for a given relationship without actually loading the models
#seeders
My 1st Laravel tip in here. Speed up your Seeders
Gariya
#collections #filter
โก ๏ธ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. #laravel #php
#responses #macros
๐ฅ You can create custom @laravelphp Response macros for common tasks, such as returning an image response, returning API responses, etc. There are many additional places within Laravel where you can make use of macros!
Marcel Pociot ๐งช
#carbon #dates
Laravel ships with two great date helpers so that you don't have to use Carbon directly ๐
#rate limiting #ddos
Laravel Tip ๐ก You can create and attach rate limiters to your routes. For example, to prevent someone from sending thousands of password reset emails.
Philo Hermans