PHPackages                             laragear/discover - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. laragear/discover

ActiveLibrary[File &amp; Storage](/categories/file-storage)

laragear/discover
=================

Discover and filter PHP Classes within a directory

v3.0.0(2mo ago)53.3k↓41.7%MITPHPPHP ^8.3CI passing

Since Mar 3Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Laragear/Discover)[ Packagist](https://packagist.org/packages/laragear/discover)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-discover/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (10)Used By (0)

Discover
========

[](#discover)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b44296da54e659f57ee7ef18856f9b23db6daa5457e6d2682d637bfbd8d12d44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f646973636f7665722e737667)](https://packagist.org/packages/laragear/discover)[![Latest stable test run](https://github.com/Laragear/Discover/workflows/Tests/badge.svg)](https://github.com/Laragear/Discover/actions)[![Codecov coverage](https://camo.githubusercontent.com/8c6ac6d38b7879cb0bb8c0d69d0b63f5c11e4b77d81c0d0c0a13e0d0b225b96d/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f446973636f7665722f67726170682f62616467652e7376673f746f6b656e3d6e47467a4d6a70486766)](https://codecov.io/gh/Laragear/Discover)[![Maintainability](https://camo.githubusercontent.com/ef96f35338dfb4c7090c479652cdd0996c9a007c8b7f169c05359f0a2c5e922a/68747470733a2f2f716c74792e73682f6261646765732f34653836653830652d623332632d343639322d386231612d3338353766626463303165642f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/Discover)[![Sonarcloud Status](https://camo.githubusercontent.com/03ccee39b625f36bf5e6eb23a0e395b27a9ba240ec48ca6f750873b3c6606e63/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f446973636f766572266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_Discover)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/11.x/octane#introduction)

Discover and filter PHP Classes within a directory.

```
use Laragear\Discover\Facades\Discover;

foreach (Discover::in('Rules') as $rule) {
    // ...
};
```

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FDiscover&hashtags=PHP,Laravel)**

Requisites
----------

[](#requisites)

- PHP 8.3 or later
- Laravel 12 or later

Installation
============

[](#installation)

You can install the package via Composer:

```
composer require laragear/discover
```

Usage
-----

[](#usage)

The `Discover` finds classes under a given project path. It contains fluent methods to filter the classes to discover, like method and property names, interfaces, traits and attributes.

Let's make a simple example: list all classes that include the method `handle()`, inside the `App\Scoreboards` or deeper.

```
use Laragear\Discover\Facades\Discover;

$classes = Discover::withMethod('handle')->in('Scoreboards')->allClasses();
```

The Discover class will automatically resolve your project path, and use your application path (`app`) and namespace (`App`) as the base to find the matching classes.

Important

The discovered classes must be [PSR-4 autoloaded](https://getcomposer.org/doc/04-schema.md#psr-4).

#### Application path and namespace

[](#application-path-and-namespace)

Most Laravel projects use the `app` and `App` as the application path and namespace, respectively. The library will use these, or any other set for your application.

To discover classes *elsewhere*, you will need to use the `at()` method to change both. If you don't set the namespace, it will be inferred from the path.

```
use Laragear\Discover\Facades\Discover;

// Discover starting at the "my-project/score" using "Score" as the base namespace.
$classes = Discover::at('score')->classes();

// Discover starting at the "my-project/match" using the "Matches" as the base namespace.
$classes = Discover::at('/match', 'Matches')->classes();
```

### Namespace

[](#namespace)

Use the `in()` method to set the base namespace to find classes. For example, if we want the classes in the `App\Scoreboards` namespace, we only need to set `Scoreboards`boards.

```
use Laragear\Discover\Facades\Discover;

$classes = Discover::in('Scoreboards')->classes();
```

### Filters

[](#filters)

You may use the included filters to find classes that are instances of another class or interfaces, or contains a given method, property or attribute.

```
use Laragear\Discover\Facades\Discover;
use App\Score\Contracts\Score;
use App\Score\Concerns\FiresEvents;
use App\Attributes\Subscribable;

// Filter all classes instances of at least one of the given classes/interfaces.
Discover::in('Scoreboards')->instancesOf(ScoreContract::class)->classes();

// Filter all classes with at least one of the given public methods.
Discover::in('Scoreboards')->withMethod('show')->classes();

// Filter all classes with at least one of the given public properties.
Discover::in('Scoreboards')->withProperty('user')->classes();

// Filter all classes with at least one of the given traits.
Discover::in('Scoreboards')->withTrait(FiresEvents::class)->classes();

// Filter all classes with at least one of the given attributes.
Discover::in('Scoreboards')->withAttribute(Subscribable::class)->classes();
```

#### Additional filters

[](#additional-filters)

Since the classes are returned as `ReflectionClass` instances inside a [Collection](https://laravel.com/docs/11.x/collections), you can further filter the list. For example, filter all the class names that don't end with `Score`.

```
use Laragear\Discover\Facades\Discover;
use Illuminate\Support\Str;

$classes = Discover::in('Scoreboards')
    ->classes()
    ->filter(fn ($class) => Str::endsWith($class->getName(), 'Score'));
```

### Retrieving classes

[](#retrieving-classes)

Once you're done building your filters, you can retrieve the found classes as a Collection using `classes()`.

```
use Laragear\Discover\Facades\Discover;

// Find all classes in `App\Scoreboards`.
$classes = Discover::in('Scoreboards')->classes();
```

The Discover class only looks for classes in the namespace set. To make the search recursive, you can use `allClasses()`, or use `recursive()` before the retrieval.

```
use Laragear\Discover\Facades\Discover;

// Find all classes in `App\Scoreboards` and deeper.
$classes = Discover::in('Scoreboards')->recursively()->classes();

// Same as...
$classes = Discover::in('Scoreboards')->allClasses();
```

In any case, the `Discoverer` itself is iterable, so you can immediately use it inside a `foreach` loop.

```
use Laragear\Discover\Facades\Discover;

foreach (Discover::recursive()->in('Scoreboards') as $class) {
    // ...
}
```

You may also pass down any method Collection method or High Order method directly, which may save you a few keystrokes.

```
use Laragear\Discover\Facades\Discover;

$classes = Discover::in('Scoreboards')->map->isFinal();
```

Outside Laravel
---------------

[](#outside-laravel)

It's possible to use the Discoverer outside Laravel projects, as it only requires the `illuminate/support` library. You may need to set your project root path manually when instancing the `Laragear\Discover\Discoverer` class.

```
use Laragear\Discover\Discoverer;

$discoverer = new Discoverer(__DIR__ . '/..');

foreach ($discoverer->at('software', 'Application')->in('Events') as $event) {
    // ...
}
```

Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties written.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Licence
=======

[](#licence)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011-2025 Laravel LLC.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance85

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~91 days

Recently: every ~85 days

Total

9

Last Release

76d ago

Major Versions

v1.0.2 → v2.0.02025-03-29

2.x-dev → v3.0.02026-03-04

PHP version history (3 changes)v1.0.0PHP ^8.1

v2.0.0PHP ^8.2

v3.0.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

[![DarkGhostHunter](https://avatars.githubusercontent.com/u/5141911?v=4)](https://github.com/DarkGhostHunter "DarkGhostHunter (15 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (1 commits)")

---

Tags

laravelclassdiscoverfinderclasses

### Embed Badge

![Health badge](/badges/laragear-discover/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-discover/health.svg)](https://phpackages.com/packages/laragear-discover)
```

###  Alternatives

[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[vinelab/cdn

Content Delivery Network (CDN) Package for Laravel

217240.8k1](/packages/vinelab-cdn)[ergebnis/classy

Provides collectors for classy constructs (classes, enums, interfaces, and traits).

382.8M20](/packages/ergebnis-classy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
