PHPackages                             wfeller/parental - 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. wfeller/parental

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

wfeller/parental
================

A simple eloquent trait that allows relationships to be accessed through child models.

0.14.0(10mo ago)01.8k1MITPHPPHP ^8.0

Since Sep 1Pushed 10mo agoCompare

[ Source](https://github.com/wfeller/parental)[ Packagist](https://packagist.org/packages/wfeller/parental)[ RSS](/packages/wfeller-parental/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (4)Versions (36)Used By (0)

Parental
========

[](#parental)

[![Plant Tree](https://camo.githubusercontent.com/82b7e7c30d073f74b47bbaaf70f5f98792426ff1bea8ee7b05c5879ac56a060c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d627269676874677265656e266c6162656c3d506c616e74253230547265652671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e6561727468253246757365727325324674726565776172652532467472656573)](https://plant.treeware.earth/wfeller/parental)[![Buy us a tree](https://camo.githubusercontent.com/15453546808b5ea47b48633f72f490420e2e41b885556eee95d7e88f4a754418/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666f722d7468652d6261646765)](https://plant.treeware.earth/wfeller/parental)

Parental is a Laravel package, forked from [calebporzio/parental](https://github.com/calebporzio/parental), that brings STI (Single Table Inheritance) capabilities to Eloquent.

### What is single table inheritance (STI)?

[](#what-is-single-table-inheritance-sti)

It's a fancy name for a simple concept: Extending a model (usually to add specific behavior), but referencing the same table.

Licence
-------

[](#licence)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/wfeller/parental) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here [offset.earth/treeware](https://plant.treeware.earth/%7Bvendor%7D/%7Bpackage%7D)

Read more about Treeware at [treeware.earth](http://treeware.earth)

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

[](#installation)

```
composer require "wfeller/parental"
```

Each time you add or remove child classes, you'll want to do the following:

```
php artisan parental:discover-children
```

This artisan command will simplify the following:

- Laravel Nova resource inheritance (when children don't already have a dedicated Nova resource)
- Adding child global scopes when querying parent

Simple Usage
------------

[](#simple-usage)

```
// The "parent"
class User extends Model
{
    //
}
```

```
// The "child"
class Admin extends User
{
    use \WF\Parental\HasParent;

    public function impersonate($user) {
        ...
    }
}
```

```
// Returns "Admin" model, but reference "users" table:
$admin = Admin::first();

// Can now access behavior exclusive to "Admin"s
$admin->impersonate($user);
```

### What problem did we just solve?

[](#what-problem-did-we-just-solve)

Without Parental, calling `Admin::first()` would throw an error because Laravel would be looking for an `admins` table. Laravel generates expected table names, as well as foreign keys and pivot table names, using the model's class name. By adding the `HasParent` trait to the Admin model, Laravel will now reference the parent model's class name `users`.

Accessing Child Models from Parents
-----------------------------------

[](#accessing-child-models-from-parents)

```
// First, we need to create a `type` column on the `users` table
Schema::table('users', function ($table) {
    $table->string('type')->nullable();
});
```

```
// The "parent"
class User extends Model
{
    use WF\Parental\HasChildren;

    protected $fillable = ['type'];
}
```

```
// A "child"
class Admin extends User
{
    use \WF\Parental\HasParent;
}
```

```
// Another "child"
class Guest extends User
{
    use \WF\Parental\HasParent;
}
```

```
// Adds row to "users" table with "type" column set to: "App/Admin"
Admin::create(...);

// Adds row to "users" table with "type" column set to: "App/Guest"
Guest::create(...);

// Returns 2 model instances: Admin, and Guest
User::all();
```

### What problem did we just solve?

[](#what-problem-did-we-just-solve-1)

Before, if we ran: `User::first()` we would only get back `User` models. By adding the `HasChildren` trait and a `type` column to the `users` table, running `User::first()` will return an instance of the child model (`Admin` or `Guest` in this case).

Type Aliases
------------

[](#type-aliases)

If you don't want to store raw class names in the type column, you can override them using the `$childTypes` property.

```
class User extends Model
{
    use \WF\Parental\HasChildren;

    protected $fillable = ['type'];

    protected $childTypes = [
        'admin' => App\Admin::class,
        'guest' => App\Guest::class,
    ];
}
```

Now, running `Admin::create()` will set the `type` column in the `users` table to `admin` instead of `App\Admin`.

This feature is useful if you are working with an existing type column, or if you want to decouple application details from your database.

Custom Type Column Name
-----------------------

[](#custom-type-column-name)

You can override the default type column by setting the `$childColumn` property on the parent model.

```
class User extends Model
{
    use \WF\Parental\HasChildren;

    protected $fillable = ['parental_type'];

    protected $childColumn = 'parental_type';
}
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance54

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 64% 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 ~92 days

Recently: every ~442 days

Total

32

Last Release

306d ago

PHP version history (3 changes)0.10PHP ^7.2

0.12.1PHP ^7.2|^8.0

0.13.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/61f8f46bedb67ee0a5472bef1ba54cf68f8594514c57404661606721dec7c7d8?d=identicon)[wfeller](/maintainers/wfeller)

---

Top Contributors

[![calebporzio](https://avatars.githubusercontent.com/u/3670578?v=4)](https://github.com/calebporzio "calebporzio (48 commits)")[![wfeller](https://avatars.githubusercontent.com/u/21337627?v=4)](https://github.com/wfeller "wfeller (20 commits)")[![dallincoons](https://avatars.githubusercontent.com/u/6494464?v=4)](https://github.com/dallincoons "dallincoons (1 commits)")[![mattstauffer](https://avatars.githubusercontent.com/u/151829?v=4)](https://github.com/mattstauffer "mattstauffer (1 commits)")[![michelbrito](https://avatars.githubusercontent.com/u/43976?v=4)](https://github.com/michelbrito "michelbrito (1 commits)")[![nickels](https://avatars.githubusercontent.com/u/9688615?v=4)](https://github.com/nickels "nickels (1 commits)")[![adriandmitroca](https://avatars.githubusercontent.com/u/3842935?v=4)](https://github.com/adriandmitroca "adriandmitroca (1 commits)")[![ziming](https://avatars.githubusercontent.com/u/679513?v=4)](https://github.com/ziming "ziming (1 commits)")[![austenc](https://avatars.githubusercontent.com/u/575421?v=4)](https://github.com/austenc "austenc (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wfeller-parental/health.svg)

```
[![Health](https://phpackages.com/badges/wfeller-parental/health.svg)](https://phpackages.com/packages/wfeller-parental)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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