larastan
larastan copied to clipboard
Added the ability to check for unnecessary collection calls on dynamic properties in NoUnnecessaryCollectionCallRule
- [X] Added or updated tests
- [ ] Documented user facing changes
- [X] Updated CHANGELOG.md
Changes
Added the ability to check for unnecessary collection calls on dynamic properties in NoUnnecessaryCollectionCallRule. E.g. in the following faulty example, instead of querying for all accounts for the user first, we build a query and execute it with the count
Bad:
User::firstOrFail()->accounts->count();
Good:
User::firstOrFail()->accounts()->count();
Also see example in this article why it's helpful and why it can cause performance issues.
Don’t use a collection to count the number of related entries.
Breaking changes