someonefamous/laravel-findby
Add dynamic finders to Eloquent models: call User::findByLastName('Smith') or User::findAllByFirstName('Bob') instead of where()->first()/get(). Works with any snake_cased field name via the FindBy trait.
Pros:
findByLastName() vs. where()->first()), improving developer productivity and readability.Cons:
find/first and get operations; does not address complex queries (e.g., joins, aggregations, or raw SQL).findBy() are model-specific and don’t integrate with Laravel’s query builder globally (e.g., no DB::findBy()).Key Use Cases:
where()->first() patterns exist.Low Risk:
composer require installation with minimal configuration.use statements (as noted in v2.0.0), which is a one-time migration.Potential Conflicts:
findByX, the trait’s dynamic method generation will fail. Requires manual resolution (e.g., renaming or excluding fields).user_id vs. userId), the package won’t work without customization.Low to Medium:
Mitigation Strategies:
Adoption Scope:
Maintenance:
Performance:
where() clauses?Alternatives:
User::findByLastName() via a global helper) achieve the same result without external dependencies?Testing:
Laravel Ecosystem:
DB::table() queries without wrapping them in a model.PHP Version:
Database Compatibility:
Assessment Phase:
where()->first() patterns).findByX methods) or non-snake_case fields.Proof of Concept:
findBy() with null values, special characters, or reserved keywords).Incremental Rollout:
use statements from SomeoneFamous\FindBy\FindBy to SomeoneFamous\FindBy\Traits\FindBy (if upgrading from v1.x).Fallback Plan:
where() clauses).Laravel Versions:
PHP Extensions:
pdo and database extensions are enabled.Third-Party Packages:
Pre-Integration:
composer.json and run composer require someonefamous/laravel-findby.Post-Integration:
where()->first() with findBy() in business logic, controllers, and services.Long-Term:
findBy() calls with native Laravel features (e.g., custom accessors or query scopes).Pros:
Cons:
Call to undefined method errors may point to the trait rather than the actual issue).Mitigation:
How can I help you explore Laravel packages today?