PHPackages                             biscofil/laravel-submodels - 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. biscofil/laravel-submodels

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

biscofil/laravel-submodels
==========================

Create Laravel submodels

v2.0.1(6y ago)416.6k[2 issues](https://github.com/biscofil/laravel-submodels/issues)mitPHP

Since Jul 25Pushed 6y agoCompare

[ Source](https://github.com/biscofil/laravel-submodels)[ Packagist](https://packagist.org/packages/biscofil/laravel-submodels)[ Docs](https://github.com/biscofil/laravelsubmodels)[ RSS](/packages/biscofil-laravel-submodels/feed)WikiDiscussions v2 Synced today

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Laravel Submodels
=================

[](#laravel-submodels)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b796a0f6a13dbee4b79e6a3ef73e4bff53dc64dc9c133a77352f3c79428ad609/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626973636f66696c2f6c61726176656c2d7375626d6f64656c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/biscofil/laravel-submodels)[![Travis](https://camo.githubusercontent.com/9f83a3dbfb059f38aecf9541d9eabe13d4129b5c3a4f314353f9f493037de9fd/68747470733a2f2f6170692e7472617669732d63692e6f72672f626973636f66696c2f6c61726176656c2d7375626d6f64656c732e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/biscofil/laravel-submodels)[![Total Downloads](https://camo.githubusercontent.com/ed2fc2290fef32c7dbd44e008f573efb83d3aa6d8743b190d52613d6bbe250a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626973636f66696c2f6c61726176656c2d7375626d6f64656c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/biscofil/laravel-submodels)[![Coverage Status](https://camo.githubusercontent.com/41af71c1e71b663c6a1bf73f497a28b39fd1f0380cc105a2e2120d541fb91a3a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f626973636f66696c2f6c61726176656c2d7375626d6f64656c732f62616467652e737667)](https://coveralls.io/github/biscofil/laravel-submodels?branch=v2)

Create submodels in Laravel

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

[](#installation)

Via Composer

```
composer require biscofil/laravel-submodels
```

Usage
-----

[](#usage)

```
>>> User::find(1)
=> App\AdminUser {#3182
     id: 1,
     first_name: "something",
     last_name: "something"
     is_admin: true,
     admin_parameter: "something"

>>> User::find(2)
=> App\User {#3164
     id: 2,
     first_name: "something",
     last_name: "something",
     is_admin: false
```

In order to accomplish this result, each Model that has to be extended must implement `getSubModelClass` that returns the right class depending on conditions.

```
class User extends Authenticatable{

    use HasSubModels;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name', 'last_name', 'is_admin'
    ];

    /**
    * @param $model
    * @return string|null
    */
   public function getSubModelClass($model){
       $class = null;
       if ($model->isAdmin()) {
           $class = AdminUser::class;
       } elseif ($model->isCustomer()) {
           $class = CustomerUser::class;
       }
       return $class;
   }

   /**
     * @param $query
     * @return mixed
     */
    public function scopeAdmins($query)
    {
        return $query->where('is_admin', '=', true);
    }

}
```

On the other side, each sub model can add the `appendedFillable` PRIVATE property that contains the list of fillable parameters. This list will be merged with the list of the parent class. The same happens for the `appendedCasts` array.

```
class AdminUser extends User{

    use HasAppendedFields;

    private $appendedFillable = [
        'admin_parameter',
        'is_a_cool_admin'
    ];

    private $appendedCasts = [
         'is_a_cool_admin' => 'bool'
    ];

    public function newQuery()
    {
        return $this->scopeAdmins(parent::newQuery());
    }

}
```

Credits
-------

[](#credits)

- [Filippo Bisconcin](https://github.com/biscofil)
- [All Contributors](../../contributors)

License
-------

[](#license)

license. Please see the [license file](license) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~27 days

Total

4

Last Release

2401d ago

Major Versions

1.0.1 → v2.0.02019-10-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/409b1429258d3daea3f934526d88ddd924fe630525c4cfc89c65ddd58316ed58?d=identicon)[biscofil](/maintainers/biscofil)

---

Top Contributors

[![biscofil](https://avatars.githubusercontent.com/u/1677625?v=4)](https://github.com/biscofil "biscofil (40 commits)")

---

Tags

hierarchical-modelslaravellaravel-frameworklaravel-modelphplaravelmodeltraithierarchysub-models

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/biscofil-laravel-submodels/health.svg)

```
[![Health](https://phpackages.com/badges/biscofil-laravel-submodels/health.svg)](https://phpackages.com/packages/biscofil-laravel-submodels)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[esensi/model

The base model traits of Esensi

20266.5k1](/packages/esensi-model)[greabock/tentacles

Da epic tentacles for Eloquent

3634.4k](/packages/greabock-tentacles)

PHPackages © 2026

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