PHPackages                             encoredigitalgroup/laravel-discovery - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. encoredigitalgroup/laravel-discovery

ActiveLibrary

encoredigitalgroup/laravel-discovery
====================================

v1.4.0(2mo ago)13.2k↓46.4%BSD-3-ClausePHPPHP ^8.3CI passing

Since Aug 31Pushed 2mo agoCompare

[ Source](https://github.com/EncoreDigitalGroup/laravel-discovery)[ Packagist](https://packagist.org/packages/encoredigitalgroup/laravel-discovery)[ RSS](/packages/encoredigitalgroup-laravel-discovery/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (16)Used By (0)

Laravel Discovery
=================

[](#laravel-discovery)

A Laravel package that automatically discovers and caches interface implementations across your codebase and vendor packages.

Features
--------

[](#features)

- **Interface Implementation Discovery**: Automatically finds all classes that implement specific interfaces
- **Caching**: Generates cached files for fast runtime lookups
- **Vendor Support**: Can search through vendor packages for implementations
- **Configurable**: Flexible configuration for search paths and interfaces
- **Artisan Command**: Simple command to trigger discovery process

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11+

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require encoredigitalgroup/laravel-discovery
```

The service provider will be automatically registered via Laravel's package auto-discovery.

Add the following to your `post-autoload-dump` script:

```
@php artisan discovery:run
```

This command will:

1. Search for all configured interfaces
2. Find implementing classes in your app, modules, and configured vendor paths
3. Generate cache files in `bootstrap/cache/discovery/`

Usage
-----

[](#usage)

### Basic Configuration

[](#basic-configuration)

Configure the discovery system using the `Discovery` configuration class:

```
use EncoreDigitalGroup\LaravelDiscovery\Support\Discovery;

// Add interfaces to discover
Discovery::config()->addInterface(YourInterface::class);

// Add specific vendors to search
Discovery::config()
    ->addVendor("laravel")
    ->addVendor("spatie");

// Or search all vendors (extremely slow, use with caution)
Discovery::config()->searchAllVendors();
```

### Retrieving Cached Results

[](#retrieving-cached-results)

Access the discovered implementations using the cache method:

```
use EncoreDigitalGroup\LaravelDiscovery\Support\Discovery;

// Get all implementations of an interface
$implementations = Discovery::cache(YourInterface::class);
```

Configuration Options
---------------------

[](#configuration-options)

### Search Paths

[](#search-paths)

The package searches in the following directories by default:

- `app/` - Your application code
- `app_modules/` or `app-modules/` - If they exist
- Configured vendor directories (when enabled)

### Cache Location

[](#cache-location)

Cache files are stored in `bootstrap/cache/discovery/` by default. Each interface gets its own cache file named after the interface (e.g., `YourInterface.php`).

Example
-------

[](#example)

```
