PHPackages                             minionfactory/model-mapper - 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. [Database &amp; ORM](/categories/database)
4. /
5. minionfactory/model-mapper

ActivePackage[Database &amp; ORM](/categories/database)

minionfactory/model-mapper
==========================

Laravel extension. Wrapper for models and raw DB::select results to map one or more attributes to other models.

v1.5.2(7mo ago)222.7k↓50%[2 PRs](https://github.com/recognizerHD/model-mapper/pulls)MITPHPPHP ^8.3CI failing

Since Oct 24Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/recognizerHD/model-mapper)[ Packagist](https://packagist.org/packages/minionfactory/model-mapper)[ RSS](/packages/minionfactory-model-mapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (41)Used By (0)

Model Mapper
============

[](#model-mapper)

[![Software License](https://camo.githubusercontent.com/9897f4467850972a38c7db9a4d38280b8fcdac0ada00e9c8c0a72ecfa8551653/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE.md)

Introduction
------------

[](#introduction)

Model Mapper is a minor change on how models are used. Many of my real world examples are contain multiple complex joins with equally complex where clauses. Using true eloquent objects for these scenarios are not beneficial. Maintenance and readability suffer, when compared to the raw equivalent SQL query that would be used.

Other times where the join is simple enough, the attribute methods are missing except for the main class that is being instantiated.

Finally, as I do most of my work with sqlsrv (Microsoft SQL Server), it has issues with dates.

This package is meant for my own usage, but is free for others who find it useful.

#### Model Mapping: AdvancedModel

[](#model-mapping-advancedmodel)

Using the model for simple updates / inserts etc is great. When the queries involve multiple joins with multiple conditions and subqueries, the model request starts to become messy. I've created two classes to handle this problem.

The first is the AdvancedModel. This overrides the default \_\_get method as well as adds modelMapper($array).

Usage:

```
$reminderText = CommonData::join('Events', 'CommonData.CommonDataID', '=', 'Events.EventsCommonID')
                          ->whereIn('EventsId', $ids)
                          ->select('CommonData.reminderemailText', 'Events.EventDate', 'Events.PriceCount')
                          ->get();

$reminderText->map(function($reminder) {
    $reminder->modelMapper([
        'EventDate'         => Events::class,
        'PriceCount'        => 'integer'
    ]);
});
```

When referencing $reminderText\[ $index \]→EventDate, it will now use the Events class to determine how to deal with the attribute instead of going to CommonData.

For each field that's being returned that is part of another model, simply add it as a key→value pair in the modelMapper mapping call.

If the attribute requires no extra altering apart from casting it to the type that it needs to be, you can use the following simple values instead of the model class:

- integer, int
- boolean, bool
- float
- double
- string, text

#### Model Mapping: AdvancedResult

[](#model-mapping-advancedresult)

The second class is AdvancedResult. This is used for raw queries as DB::select(...) returns a collection. Each of the attributes can be mapped to a model. If the third parameter is supplied as true, it returns a single result. This is the object and not a collection.

```
$asdf = DB::select("SELECT TOP 3 * FROM Events INNER JOIN CommonData ON ...");

// The first argument is passed by reference so there's no need to set the variable to be returned.
// The second argument is optional, if you want to set it later.
AdvancedResult::make($asdf, [
    'EventDate'         => Events::class,
    'reminderemailText' => CommonData::class,
    'PriceCount'        => 'integer'
]);

// This is how you would call the argument later.
$asdf->map(function($record){
    $record->modelMapper([
        'EventDate'  => Events::class,
        'PriceCount' => 'integer'
    ]);
    return $record;
});
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance77

Regular maintenance activity

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 87.5% 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 ~76 days

Recently: every ~82 days

Total

34

Last Release

236d ago

PHP version history (4 changes)v1.1.0PHP &gt;=7.0

v1.4.1PHP &gt;=7.4

v1.4.7PHP ^8.1

v1.5.2PHP ^8.3

### Community

Maintainers

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

---

Top Contributors

[![recognizerHD](https://avatars.githubusercontent.com/u/1222899?v=4)](https://github.com/recognizerHD "recognizerHD (126 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![pauldwarren](https://avatars.githubusercontent.com/u/34344293?v=4)](https://github.com/pauldwarren "pauldwarren (6 commits)")

---

Tags

laravelmodeleloquentmapper

### Embed Badge

![Health badge](/badges/minionfactory-model-mapper/health.svg)

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

###  Alternatives

[sleimanx2/plastic

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch by providing a fluent syntax for mapping , querying and storing eloquent models.

508141.9k1](/packages/sleimanx2-plastic)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)

PHPackages © 2026

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