7
🔥 Create traits for relationships you commonly use in your models to make your codebase cleaner, simpler, and more consistent ✨
Laravel Tip: Abstract relations you commonly use to a trait. It’s a DRY approach that keeps your models thin.
🔥 This week's code tips for Laravel developers
Lots of cool stuff from @enunomaduro and two competing JSON tips 💪
7
Laravel Tip: Abstract relations you commonly use to a trait. It’s a DRY approach that keeps your models thin.
6
Pest reminder: if you know how to test something, "not()" lets you test its opposite. ✅
5
PHP reminder: you can define your class properties directly on the constructor. ✅
4
PHP reminder: The "declare(strict_types = 1);" directive enables strict mode. In strict mode, only a variable of exact type of the “type declaration” will be accepted, or a "TypeError" will be thrown. ✅
3
PHP reminder: you can use the method "__toString()" to specify the string representation of an object. ✅
2
Had no idea you could have PHP throw a built-in exception when decoding JSON -- I've always done this manually until today 😭
1
🔥 A way to check if a string contains valid JSON: just decode it, encode it again, and check if it matches the original value #php
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.