PHPackages                             grizzlyware/model-swapper - 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. grizzlyware/model-swapper

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

grizzlyware/model-swapper
=========================

Swap vendor models out for your own implementations, on the fly

v2.0.1(2y ago)0907[3 PRs](https://github.com/grizzlyware/model-swapper/pulls)MITPHPPHP ^8.1CI passing

Since Dec 11Pushed 1w ago1 watchersCompare

[ Source](https://github.com/grizzlyware/model-swapper)[ Packagist](https://packagist.org/packages/grizzlyware/model-swapper)[ Docs](https://github.com/grizzlyware/model-swapper)[ GitHub Sponsors](https://github.com/grizzlyware)[ RSS](/packages/grizzlyware-model-swapper/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (4)Versions (13)Used By (0)

Swap vendor models out for your own implementations, on the fly
===============================================================

[](#swap-vendor-models-out-for-your-own-implementations-on-the-fly)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ba6098d47f54045b608b05bb0fea2f3a5d5b7067f5edf40a2eafce0a2752aa5a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772697a7a6c79776172652f6d6f64656c2d737761707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grizzlyware/model-swapper)[![Tests](https://github.com/grizzlyware/model-swapper/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/grizzlyware/model-swapper/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/2a34a6c9df4ad92270f8cf50755ea1a69ddb2c512310a28631991a0779602a56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772697a7a6c79776172652f6d6f64656c2d737761707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grizzlyware/model-swapper)

This package can be used to use your own applications implementation of a model which has been provided by a vendor package. This can be useful to manipulate behaviour on a model, access protected properties or use classes in your own namespace.

Extending a vendor's class is already possible, but you cannot change vendors invocation of the class. All references will still point to the original class name and namespace.

This package will change the actual class that is returned from Eloquent query builders, including `all()`, `get()`, `first()`, `findOrFail()` etc.

For example:

```
// Code which may exist out of your control, in a vendor's package for example
\Vendor\Package\Models\CountryCode::firstOrFail()
// \Vendor\Package\Models\CountryCode is returned

/**
* After using Model Swapper
*/

\Vendor\Package\Models\CountryCode::firstOrFail()
// \App\Models\CountryCode is returned
```

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

[](#installation)

You can install the package via composer:

```
composer require grizzlyware/model-swapper
```

Usage
-----

[](#usage)

```
use Grizzlyware\ModelSwapper\Facades\ModelSwapper;
use Grizzlyware\ModelSwapper\Traits\IsReplacementModel;

// Add the IsReplacementModel trait to your replacement class
class YourApplicationsClass extends ClassFromVendorPackage
{
    use IsReplacementModel;
}

// Swap the model out - this would usually be in your AppServiceProvider, in the boot method.
ModelSwapper::swap(
    ClassFromVendorPackage::class,
    YourApplicationsClass::class
);

// From now on, all queries for ClassFromVendorPackage will return instances of YourApplicationsClass
```

### Advanced usage

[](#advanced-usage)

```
use Grizzlyware\ModelSwapper\Contracts\ModelSwapperServiceInterface;

// Or typehint from the container
public function __construct(ModelSwapperServiceInterface::class $modelSwapper)

// Or resolve from the container
resolve(ModelSwapperServiceInterface::class)->swap(
    ClassFromVendorPackage::class,
    YourApplicationsClass::class
);

// You can access the original, non-replaced model query like so:
YourApplicationsClass::replacedModelQuery()->firstOrFail();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please notify  about any security vulnerabilities, do not open an issue for them.

Credits
-------

[](#credits)

- [Grizzlyware Ltd](https://github.com/grizzlyware)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance64

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 78% 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 ~224 days

Total

3

Last Release

851d ago

Major Versions

v1.0 → v2.02023-08-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8484110cb3665a1502f4095420c5a646e6694f3c42d63a6fcc8f5fd1736a755?d=identicon)[mewejo](/maintainers/mewejo)

---

Top Contributors

[![mewejo](https://avatars.githubusercontent.com/u/1097093?v=4)](https://github.com/mewejo "mewejo (71 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

laravelgrizzlywaremodel-swapper

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/grizzlyware-model-swapper/health.svg)

```
[![Health](https://phpackages.com/badges/grizzlyware-model-swapper/health.svg)](https://phpackages.com/packages/grizzlyware-model-swapper)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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