PHPackages                             michael-rubel/laravel-enhanced-container - 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-enhanced-container

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

michael-rubel/laravel-enhanced-container
========================================

This package provides DX tweaks for Service Container in Laravel.

13.0.3(1y ago)88110.7k↓40.1%33MITPHPPHP ^8.3|^8.4

Since May 16Pushed 1y ago5 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (34)Used By (3)

[![Method binding with Service Container   Call Proxy](https://private-user-images.githubusercontent.com/37669560/261450366-f7f2b1d0-68cb-485b-bdc5-93ea109f7e1d.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NTE2NjMsIm5iZiI6MTc3NDY1MTM2MywicGF0aCI6Ii8zNzY2OTU2MC8yNjE0NTAzNjYtZjdmMmIxZDAtNjhjYi00ODViLWJkYzUtOTNlYTEwOWY3ZTFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI3VDIyNDI0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU0ZjNiYzc4NmQ3MTczNTIwYWNmY2UyNjZlMzZlYzI4MWQ0NjY2YjdlZWZkMjM2ZTMyZjgwNGVmNWJiY2IyZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.pk5-YTDMd3TCmOEHEY5F0nDjW8vL-PTr-FbjQzxCKW4)](https://private-user-images.githubusercontent.com/37669560/261450366-f7f2b1d0-68cb-485b-bdc5-93ea109f7e1d.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NTE2NjMsIm5iZiI6MTc3NDY1MTM2MywicGF0aCI6Ii8zNzY2OTU2MC8yNjE0NTAzNjYtZjdmMmIxZDAtNjhjYi00ODViLWJkYzUtOTNlYTEwOWY3ZTFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI3VDIyNDI0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU0ZjNiYzc4NmQ3MTczNTIwYWNmY2UyNjZlMzZlYzI4MWQ0NjY2YjdlZWZkMjM2ZTMyZjgwNGVmNWJiY2IyZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.pk5-YTDMd3TCmOEHEY5F0nDjW8vL-PTr-FbjQzxCKW4)

Laravel Enhanced Container
==========================

[](#laravel-enhanced-container)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b8042d2fa9b7b4a1e49cf2be26ce8bef1d46f5c9357e9c5510004b2e9aa5d8bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/michael-rubel/laravel-enhanced-container)[![Total Downloads](https://camo.githubusercontent.com/4e33bfbf45d9be57075f9d13712d12a384ce52854e94d6a47a9d08c685be70f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/michael-rubel/laravel-enhanced-container)[![Code Quality](https://camo.githubusercontent.com/783b67ef2f6c9b87c067e3c615a4dd18438a46f19bac3665b0daaf4726040c27/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/michael-rubel/laravel-enhanced-container/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/30dbce4128b283c9488600604d121c4ddf25f871c0cb05fa45b9316c1dbbe478/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/michael-rubel/laravel-enhanced-container/?branch=main)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e2b29db382dbaecbd7c0cb07c359e87ce107d43dd8b451a924fd4268e5adabfd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d7465737473266c6f676f3d676974687562)](https://github.com/michael-rubel/laravel-enhanced-container/actions)[![PHPStan](https://camo.githubusercontent.com/08e64f4a1fd34ac4d833db57f645cde579375b01b985005417710310c8507c61/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d69636861656c2d727562656c2f6c61726176656c2d656e68616e6365642d636f6e7461696e65722f7068707374616e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d6c6172617374616e266c6f676f3d6c61726176656c)](https://github.com/michael-rubel/laravel-enhanced-container/actions)

This package provides additional features for Laravel's Service Container.

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

[](#standwithukraine)

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

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Resolve contextual binding outside of constructor](#resolve-contextual-binding-outside-of-constructor)
    - [Method binding](#method-binding)
    - [Method forwarding](#method-forwarding)

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

[](#installation)

Install the package via composer (Laravel 11):

```
composer require michael-rubel/laravel-enhanced-container
```

If you need the package for older versions of Laravel, check [changelog](https://github.com/michael-rubel/laravel-enhanced-container/releases).

Usage
-----

[](#usage)

### Resolve contextual binding outside of constructor

[](#resolve-contextual-binding-outside-of-constructor)

```
call(ServiceInterface::class, context: static::class);

// The `call` method automatically resolves the implementation from the interface you passed.
// If you pass the context, the proxy tries to resolve contextual binding instead of global binding first.
```

[🔝 back to contents](#contents)

### Method binding

[](#method-binding)

This feature makes it possible to override the behavior of methods accessed using the `call`.

Assuming that is your function in the service class:

```
class Service
{
    public function yourMethod(int $count): int
    {
        return $count;
    }
}
```

Bind the service to an interface:

```
$this->app->bind(ServiceInterface::class, Service::class);
```

Call your service method through container:

```
call(ServiceInterface::class)->yourMethod(100);
```

For example in feature tests:

```
$this->app->bind(ApiGatewayContract::class, InternalApiGateway::class);

bind(ApiGatewayContract::class)->method('performRequest', function ($service, $app, $params) {
    // Note: you can access `$params` passed to the method call.

    return true;
});

$apiGateway = call(ApiGatewayContract::class);
$request = $apiGateway->performRequest();
$this->assertTrue($request);
```

Note: if you rely on interfaces, the proxy will automatically resolve bound implementation for you.

#### Note for package creators

[](#note-for-package-creators)

If you want to use method binding in your own package, you need to make sure the [`LecServiceProvider`](https://github.com/michael-rubel/laravel-enhanced-container/blob/main/src/LecServiceProvider.php) registered before you use this feature.

```
$this->app->register(LecServiceProvider::class);
```

[🔝 back to contents](#contents)

### Method forwarding

[](#method-forwarding)

This feature automatically forwards the method if it doesn't exist in your class to the second one defined in the forwarding configuration.

You can define forwarding in your ServiceProvider:

```
use MichaelRubel\EnhancedContainer\Core\Forwarding;

Forwarding::enable()
    ->from(Service::class)
    ->to(Repository::class);
```

You can as well use chained forwarding:

```
Forwarding::enable()
    ->from(Service::class)
    ->to(Repository::class)
    ->from(Repository::class)
    ->to(Model::class);
```

#### Important notes

[](#important-notes)

- Pay attention to which internal instance you're now working on in `CallProxy` when using forwarding. The instance may change without your awareness. If you interact with the same methods/properties on a different instance, the `InstanceInteractionException` will be thrown.
- If you use `PHPStan/Larastan` you'll need to add the `@method` docblock to the service to make it static-analyzable, otherwise it will return an error that the method doesn't exist in the class.

[🔝 back to contents](#contents)

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 99.7% 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 ~34 days

Recently: every ~66 days

Total

28

Last Release

530d ago

Major Versions

8.1.2 → 9.0.02022-07-08

9.3.0 → 10.x-dev2022-11-21

10.0.3 → 11.0.02023-01-18

11.0.1 → 12.0.02024-03-12

12.0.0 → 13.0.02024-08-21

PHP version history (5 changes)7.4.1PHP ^8.0|^8.1

9.2.1PHP ^8.0

11.0.0PHP ^8.1

13.0.0PHP ^8.3

13.0.3PHP ^8.3|^8.4

### 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 (617 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

containerenhancedioc-containerlaravellooking-for-contributorsphpservice-containerlaravelmichael-rubellaravel-enhanced-containerlec

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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