PHPackages                             michael-rubel/laravel-auto-binder - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. michael-rubel/laravel-auto-binder

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

michael-rubel/laravel-auto-binder
=================================

This package adds the possibility to bind interfaces to implementations in the Service Container by scanning the specified project folders. This helps avoid manually registering container bindings when the project needs to bind a lot of interfaces to its implementations.

6.0.0(2y ago)7514.9k6MITPHPPHP ^8.0

Since Jan 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/michael-rubel/laravel-auto-binder)[ Packagist](https://packagist.org/packages/michael-rubel/laravel-auto-binder)[ Docs](https://github.com/michael-rubel/laravel-auto-binder)[ Fund](https://paypal.com/donate/?hosted_button_id=KHLEL8PFS4AXJ)[ RSS](/packages/michael-rubel-laravel-auto-binder/feed)WikiDiscussions main Synced today

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

[![Automated container bindings](https://user-images.githubusercontent.com/37669560/202474138-d1bfc486-3f13-4383-bb39-3faf3118f75f.png)](https://user-images.githubusercontent.com/37669560/202474138-d1bfc486-3f13-4383-bb39-3faf3118f75f.png)

Laravel Auto-Binder
===================

[](#laravel-auto-binder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c5d8654eefe56717f3275a54ab5436ec6caa7c3eb0f0e3da6698f3ed70773549/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/michael-rubel/laravel-auto-binder)[![Total Downloads](https://camo.githubusercontent.com/a815d602a07a85a4db9b0a44aafdca5b2a3bc6354ae0160a2df37f1ed15f1714/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/michael-rubel/laravel-auto-binder)[![Code Quality](https://camo.githubusercontent.com/62fbe54ae3d60723d02360a127cb71d5aeb5431f20cfc465fda8baa08f94a7ef/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/michael-rubel/laravel-auto-binder/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/13aab4ed912cf51115269a67bbbc5a2c9d8d24fd512efe2093035d7daeac0c85/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/michael-rubel/laravel-auto-binder/?branch=main)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b2bf3095657e68edaf6131665dc3f0ed86b86b0a2c6ac86110600e54b01c8ebe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d7465737473266c6f676f3d676974687562)](https://github.com/michael-rubel/laravel-auto-binder/actions)[![PHPStan](https://camo.githubusercontent.com/01b1478fadac60c127d552f6f200da370528af5b9671f825f25e8a232a6ca8e6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d69636861656c2d727562656c2f6c61726176656c2d6175746f2d62696e6465722f7068707374616e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d6c6172617374616e266c6f676f3d6c61726176656c)](https://github.com/michael-rubel/laravel-auto-binder/actions)

This package adds the possibility to bind interfaces to concrete classes in the Service Container by scanning the specified project folders. This helps avoid manually registering container bindings when the project needs to bind a lot of interfaces to its implementations.

---

The package requires `PHP 8` or higher and `Laravel 9` or higher.

\#StandWithUkraine
------------------

[](#standwithukraine)

[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

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

[](#installation)

Install the package using composer:

```
composer require michael-rubel/laravel-auto-binder
```

Usage
-----

[](#usage)

Define in your ServiceProvider:

```
AutoBinder::from(folder: 'Services')
    ->as('singleton')
    ->bind();
```

Assuming you have your services in the `App\Services` and its interfaces in the `App\Services\Interfaces`, the package will register binding for each pair of class and interface:

```
$this->app->singleton(AuthServiceInterface::class, AuthService::class);
$this->app->singleton(UserServiceInterface::class, UserService::class);
$this->app->singleton(CompanyServiceInterface::class, CompanyService::class);
...
```

### Customization

[](#customization)

If you need to customize the base path or namespace, you can use following methods:

```
AutoBinder::from(folder: 'Services')
    ->basePath('app/Domain')
    ->classNamespace('App\\Domain')
    ->interfaceNamespace('App\\Domain\\Interfaces')
    ->bind();
```

This configuration would look for classes in the `app/Domain/Services` folder, use `App\\Domain` namespace and apply interfaces from `App\\Domain\\Interfaces` namespace with `ClassNameInterface` naming convention.

If you need to change the naming convention of your interfaces, you can specify the namespace and name you prefer:

```
AutoBinder::from(folder: 'Services')
    ->interfaceNaming('Contract')
    ->bind();
```

This configuration scans the `app/Services` folder with `App\\Services` namespace, `App\\Services\\Contracts` interface namespace and `ClassNameContract` interface naming convention.

### Excluding subfolders from scan

[](#excluding-subfolders-from-scan)

You might as well exclude subdirectories from the scan of the root directory:

```
AutoBinder::from(folder: 'Services')
    ->exclude('Traits', 'Components')
    ->bind();
```

### Dependency injection

[](#dependency-injection)

If you want to inject dependencies to your services while scanning, you can use `when` method:

```
AutoBinder::from(folder: 'Services')
    ->when(ExampleServiceInterface::class, function ($app, $service) {
        return new ExampleService($app);
    })
    ->bind();
```

Passing a concrete class as well as an interface is possible, but keep in mind interfaces have a higher priority when applying dependencies.

### Scanning multiple folders at once

[](#scanning-multiple-folders-at-once)

If you pass multiple folders, the `from` method will return an instance of `Illuminate/Support/Collection`. Assuming that, you can loop over your `AutoBinder` class instances with access to internal properties.

For example:

```
AutoBinder::from('Services', 'Models')->each(
    fn ($binder) => $binder->basePath('app')
        ->classNamespace('App\\Domain')
        ->interfaceNamespace("App\\Domain\\$binder->classFolder\\Interfaces")
        ->as('singleton')
        ->bind()
);
```

### Caching

[](#caching)

The package will cache your bindings to avoid redundant folder scans during the application bootstrapping process.

If you want cache to be disabled, you may use `withoutCaching` method on the AutoBinder instance, e.g.:

```
AutoBinder::from(folder: 'Services')
    ->withoutCaching()
    ->as('singleton')
    ->bind();
```

You can as well clear the cache for specific folder by using an Artisan command:

```
php artisan binder:clear Services,Models
```

Note that for the command to work you should use the folder name you passed to the AutoBinder instance in the `from` method. Also, the cache will be ignored in the `local` environment.

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 99.6% 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 ~56 days

Recently: every ~104 days

Total

15

Last Release

843d ago

Major Versions

2.0.0 → 4.0.02022-06-23

4.1.0 → 5.0.02022-07-11

5.1.7 → 6.0.02024-03-12

PHP version history (2 changes)2.0.0PHP ^8.0|^8.1

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c060c69332d50a7cb290529ad84a7f216dec94d59950db7446dc93208787083?d=identicon)[michael-rubel](/maintainers/michael-rubel)

---

Top Contributors

[![michael-rubel](https://avatars.githubusercontent.com/u/37669560?v=4)](https://github.com/michael-rubel "michael-rubel (239 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

automationbindingscontainerioc-containerlaravellooking-for-contributorsphplaravelmichael-rubellaravel-auto-binder

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/michael-rubel-laravel-auto-binder/health.svg)

```
[![Health](https://phpackages.com/badges/michael-rubel-laravel-auto-binder/health.svg)](https://phpackages.com/packages/michael-rubel-laravel-auto-binder)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)[tapp/filament-form-builder

User facing form builder using Filament components

132.4k3](/packages/tapp-filament-form-builder)

PHPackages © 2026

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