lorisleiva/lody
Lody loads files or PHP classes from one or more paths as a Laravel LazyCollection. Discover classes via PSR-4 resolution, then filter (e.g., non-abstract, instance of) and iterate to register or process them. Configurable path and classname resolving.
app/Plugins/Payment/), and Lody auto-discovers and registers them based on traits/interfaces (e.g., PaymentGateway). This reduces onboarding friction and accelerates feature delivery for SaaS platforms, CMS, or internal tools.register() calls in service providers for classes like EventListeners, Policies, or Rules. By scanning directories and filtering via traits/methods (e.g., hasTrait('ShouldQueue')), teams avoid manual updates when adding new classes, scaling effortlessly.hasTrait('Serializable')->when(fn() => config('features.enabled'))). This supports gradual rollouts, A/B testing, or tenant-specific configurations without refactoring core logic.generateTestData() or mock() to automate test setup, improving CI/CD efficiency and test coverage. Reduces flaky tests by ensuring consistent, dynamic test data pipelines.QueuedCommand) to build self-documenting CLI tools that adapt to new requirements. Ideal for admin panels, developer tools, or internal automation.hasMethod('legacyProcess')) and wrapping them in modern interfaces (e.g., Processable). Lowers migration risk by incrementally adopting new patterns.app/Domain/Users/Commands/) to enforce consistent patterns across repositories, services, and use cases. Supports bounded contexts in large applications.plugins/payment-stripe/src/) and Lody auto-registers them.Configurable to support runtime overrides (e.g., config('services.'.classname)).PaymentGateway, AuthProvider).vendor/ for implementations of custom interfaces).resolveClassnameUsing, but expect additional maintenance.SplFileInfo, ReflectionClass, or get_declared_classes().class_alias() or get_declared_classes().setBasePath() or adapt the logic.spl_file_info observers.*"Lody is a developer productivity multiplier for Laravel projects. It automates the discovery and registration of classes—like plugins, workflow nodes, or event listeners—so teams can build modular, extensible systems without manual configuration. For example:
app/Plugins/ and Lody auto-registers it if it implements PaymentGateway.register() calls in service providers, freeing engineers to focus on features.generateTestData(), reducing flaky tests in CI/CD pipelines.This is a low-risk, high-reward investment for teams scaling Laravel applications, with no vendor lock-in (MIT license) and minimal maintenance overhead."*
*"Lody solves the ‘where do I register this?’ problem in Laravel. Instead of manually adding classes to service providers, facades, or config files, you:
app/Workflow/Nodes/).Lody::classes('app/Workflow/Nodes')->isInstanceOf(Node::class)->each(...)).Key benefits:
hasTrait('ShouldQueue')), inheritance (isInstanceOf(PaymentGateway::class)), or methods (hasMethod('execute')) to fine-tune discovery.vendor/ for third-party implementations.base_path(), app_path(), and Laravel’s config system for conditional loading.Use cases we’ve validated:
Getting started is trivial:
composer require lorisleiva/lody
Then replace manual registrations like this:
// Before (manual)
$this->app->bind('payment.stripe', StripeGateway::class);
// After (dynamic)
Lody::classes('app/Gateways/Payment')
->isInstanceOf(PaymentGateway::class)
->each(fn(string $class) => $this->app->bind('payment.'.$class, $class));
No breaking changes, just less busywork."*
*"Lody is your Swiss Army knife for class discovery in Laravel. Need to find all classes in a directory that implement an interface? Filter by trait? Check for a specific method? Done in one line:
Lody::classes('app/Commands')
->hasTrait('QueuedCommand')
->each(fn(string $class) => Artisan::register($class));
Why you’ll love it:
scandir() + ReflectionClass hell. Lody processes files/classes on-demand, saving memory.composer.json autoloading, so it works out of the box—even for vendor classes.base_path(), app_path(), and integrates with Laravel’s service container.Pro tip: Combine with when() to load classes conditionally:
Lody::classes('app/Features')
->hasMethod('isEnabled')
How can I help you explore Laravel packages today?