Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lody Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Load files and classes as lazy collections in Laravel.

Frequently asked questions about Lody
How do I install Lody in a Laravel project?
Run `composer require lorisleiva/lody` in your project directory. No additional configuration is needed for basic usage, though you can customize path resolution or classname logic if required.
Can Lody scan files outside Laravel’s base path?
Yes, by default paths are resolved relative to `base_path()`, but you can override this with `Lody::resolvePathUsing()` to handle absolute paths or custom logic. For example, pass a callback that returns untouched paths starting with `/`.
Does Lody support non-PSR-4 classname resolution?
Lody uses PSR-4 mappings from `composer.json` by default, but you can customize classname resolution with `Lody::resolveClassnameUsing()` to support legacy namespaces or custom rules.
How does lazy loading work in Lody?
Lody returns a `LazyCollection`, meaning classes/files are only loaded when iterated (e.g., via `each()` or `toArray()`). This avoids memory issues with large directories. Use `count()` to check how many items exist before processing.
What Laravel versions does Lody support?
Lody is optimized for Laravel 11+ (PHP 8.1+), but its core functionality works in any PHP environment. The package is actively maintained and supports modern Laravel features like PSR-4 autoloading.
Can I filter classes by interface or trait?
Yes, Lody provides fluent methods like `isInstanceOf()` for interfaces or `hasTrait()` for traits. For example, `Lody::classes('path')->isInstanceOf(Contract::class)` filters classes implementing a specific interface.
How do I test Lody in unit tests?
Mock the `Lody` facade or use `ClassnameLazyCollection` directly in tests. For example, inject the collection into your service and assert filtered results without hitting the filesystem.
Will Lody work with plugins or marketplace integrations?
Absolutely. Lody’s lazy loading and PSR-4 support make it perfect for dynamic plugin discovery. Scan a `plugins/` directory, filter by interfaces (e.g., `PluginContract`), and auto-register them at runtime.
Are there performance concerns with large directories?
Lazy loading mitigates overhead, but benchmark with `count()` before `each()` for directories with 10,000+ files. For critical paths, consider caching results or pre-loading during boot.
What alternatives exist to Lody for class discovery?
Manual `glob()` + `ReflectionClass` or Symfony’s `Finder` are alternatives, but Lody offers a Laravel-specific fluent API with PSR-4 integration and lazy evaluation. For real-time file watching, combine Lody with `fsnotify` or `spatie/laravel-activitylog`.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope