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
Laravel Auto Discoverer

Laravel Auto Discoverer Laravel Package

spatie/laravel-auto-discoverer

Fast, cached discovery of PHP structures in your codebase. Find classes, interfaces, traits, and enums by conditions like “implements interface” or “uses trait,” and get rich metadata. Ideal for automation, registration, and scanning in production.

View on GitHub
Deep Wiki
Context7

Automatically discover structures within your PHP application

Frequently asked questions about Laravel Auto Discoverer
How do I discover all classes implementing a specific interface in my Laravel app?
Use the fluent API: `Discover::in(app_path())->classes()->implementing(YourInterface::class)->get()`. This returns an array of fully qualified class names matching your criteria. The package scans your codebase recursively by default.
Does this package work with Laravel 8, 9, or 10?
Yes, **spatie/laravel-auto-discoverer** is fully compatible with Laravel 8+. It leverages PHP 8.1+ features and integrates cleanly with Laravel’s service container and caching systems. No Laravel-specific versioning issues exist.
Can I filter classes by modifiers like `abstract` or `final` in Laravel?
Absolutely. Use `withModifier(Modifier::ABSTRACT)` or `withModifier(Modifier::FINAL)` to filter classes. For example: `Discover::classes()->withModifier(Modifier::FINAL)->get()`. This is especially useful for enforcing immutability in services or commands.
How does caching work in production? Will it slow down my app?
The package includes a built-in cache layer that stores discovery results. By default, it uses Laravel’s cache driver. Discovery becomes near-instant in production after the first run, with zero runtime overhead for subsequent requests.
Can I use this to auto-wire services in Laravel’s service container?
Yes, this is a common use case. Discover all implementations of an interface (e.g., `RepositoryInterface`) and dynamically bind them to the container. Example: `app()->bind(RepositoryInterface::class, fn() => new DiscoveredRepository())`.
What metadata is available for each discovered structure?
Each discovered class, interface, or trait includes metadata like file path, namespace, modifiers (abstract/final/static), and whether it implements specific interfaces. This is useful for advanced filtering or logging purposes.
How do I clear the cache if my codebase changes?
Use Laravel’s cache clearing commands: `php artisan cache:clear` or `php artisan config:clear`. The package automatically invalidates cached discovery when these commands run, ensuring you always get up-to-date results.
Is there a performance impact when scanning large codebases?
The package is optimized for speed. Discovery is parallelized by default (using `amphp/parallel` if installed) and cached. For very large projects, consider limiting the scan scope with `Discover::in('app/Modules')->...` to reduce overhead.
Can I use this to build a plugin system for Laravel?
Yes, this is a great fit. Discover all classes annotated with `@Component` or implementing `PluginInterface`, then dynamically load them. Example: `Discover::classes()->implementing(PluginInterface::class)->get()`.
Are there alternatives to this package for Laravel?
Alternatives include `illuminate/support` (Laravel’s built-in reflection tools) or `phpDocumentor/reflection-docblock`. However, **spatie/laravel-auto-discoverer** offers a more fluent API, built-in caching, and advanced filtering (e.g., by modifiers or interfaces) tailored for Laravel’s ecosystem.
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.
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
anil/file-picker
broqit/fields-ai