8
π₯ You can add a messages() method to form requests to customize their validation error messages
β To customise a validation message for a request in @laravelphp , you can add a message
function to a form request. Very handy!
#laravel #php
π₯ This week's code tips for Laravel developers
𧡠A weekly thread
8
β To customise a validation message for a request in @laravelphp , you can add a message
function to a form request. Very handy!
#laravel #php
7
π₯Another amazing #Laravel feature!π₯
We often write if statements to check if a value is present on a request or not.
You can simplify it with the whenFilled() helper.
πIf you find this useful, consider clicking the button that says Retweet. It's a very cool button!
6
Does your @laravelphp application have 0 tests? Here is one test you can easily add to get started. It's probably the most important test β in web projects β and it has an enormous value.
β Ensures your application boots. β β Ensures the home page can be loaded. π¨
5
If youβre returning a fully qualified class name, you can use the class-name
docblock. You can specify a base class or interface between <>
And of course, you can also return an array of class-name
s too π
#php
4
This pattern is brilliant and can make your code much more clean and consistent
The tweet is from last year, but it's still very relevant
3
β‘οΈ Database Tip
You don't have to execute multiple queries to calculate different aggregates. With the filter clause you can narrow the rows which should be included for the calculation. So you may need to scan the table only once, the performance impact can be massive π₯
2
π₯ Simple typehints and annotations go a long way
Even without any docblocks, this code is perfectly understandable by both developers and IDEs
Writing code like this: π Prevents bugs using type safety π Makes the code self-documenting π Takes only a few seconds to implement
1
π₯ I often find myself keeping validation rules in a method on the model. This lets me reuse them wherever I may need - including in controllers or form requests.
We're writing a book, you can get it for free here. We're writing a book! Join the early access to get it for free.