PHPackages                             tmsllc/laravel-extra-field - 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. tmsllc/laravel-extra-field

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

tmsllc/laravel-extra-field
==========================

A package to enable assigning extra fields to Eloquent Models

1.0.0(2y ago)01.7k↓50%1MITPHPPHP ^8.0

Since May 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/tmsllc/laravel-extra-field)[ Packagist](https://packagist.org/packages/tmsllc/laravel-extra-field)[ Docs](https://github.com/tmsllc/laravel-extra-field)[ RSS](/packages/tmsllc-laravel-extra-field/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

laravel-extra-field
===================

[](#laravel-extra-field)

[![Laravel 9.0](https://camo.githubusercontent.com/29c8bfc0a9dfb13c56994b26528227441c0a86c440ebf535d072074c955996f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e302d6634363435662e737667)](https://camo.githubusercontent.com/29c8bfc0a9dfb13c56994b26528227441c0a86c440ebf535d072074c955996f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e302d6634363435662e737667)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)

A package to enable assigning extra fields to Eloquent Models

Contact Me
----------

[](#contact-me)

You can check all of my information by [Checking my website](https://transport-system.com/).

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

[](#installation)

You can install the package via composer:

```
composer require tmsllc/laravel-extra-field
```

The package will automatically register itself.

You must publish the migration with:

```
php artisan vendor:publish --provider="TMSLLC\ExtraField\ExtraFieldServiceProvider" --tag="migrations"
```

Migrate the `extras` &amp; `extra_values` table:

```
php artisan migrate
```

Optionally you can publish the config-file with:

```
php artisan vendor:publish --provider="TMSLLC\ExtraField\ExtraFieldServiceProvider" --tag="config"
```

This is the contents of the file which will be published at `config/extra-field.php`

```
return [

    /*
     * The class name of the extra model that holds all extras.
     *
     * The model must be or extend `TMSLLC\ExtraField\Extra`.
     */
    'extra_model' => TMSLLC\ExtraField\Extra::class,

    /*
     * The class name of the extra value model that holds all values.
     *
     * The model must be or extend `TMSLLC\ExtraField\ExtraValue`.
     */
    'extra_value_model' => TMSLLC\ExtraField\ExtraValue::class,

    /*
     * The name of the column which holds the ID of the model related to the extra values.
     *
     * You can change this value if you have set a different name in the migration for the extra_values table.
     */
    'model_primary_key_attribute' => 'model_id',

    /*
     * The name of the column which holds the Class Name of the model related to the extras.
     *
     * You can change this value if you have set a different name in the migration for the extras table.
     */
    'model_name_attribute' => 'model_class',
];
```

Usage
-----

[](#usage)

Add the `HasExtraFields` trait to a model you like to use extras on.

```
use TMSLLC\ExtraField\HasExtraFields;

class YourEloquentModel extends Model
{
    use HasExtraFields;
}
```

### Add a new extra field and value

[](#add-a-new-extra-field-and-value)

You can add a new extra field like this:

```
$extra_field = $model->addExtraField('fieldName' , 'fieldType');

//assign value
$extra_field = $model->addExtraValue($extra_field->id , 'filedValue');

//assign value for other instance no need to add extra field again
$extra_field = $otherModel->addExtraValue($extra_field->id , 'filedValue');

//for another instance
$extra_field = $anotherModel->addExtraValue($extra_field->id , 'filedValue');
```

### Add a new extra field string type and assign value

[](#add-a-new-extra-field-string-type-and-assign-value)

if you want to add a new string extra field for your model you can do it like this:

```
$model->addStringExtraValue('fieldName' , 'filedValue');

//you can repeat for other object
$otherModel->addExtraValue('fieldName', 'filedValue');
```

### Retrieve data

[](#retrieve-data)

```
// will give array of all extra fields with associated values
$model->getExtras(); // ['fieldName1' => 'filedValue' , 'fieldName2' => 'filedValue']

$model->extras(); // will return a collection of TMSLLC\ExtraField\Extra

$model->extraValues ; //will return a collection of TMSLLC\ExtraField\ExtraValue

$model->extraValues() ; // will return hasMany Relation of TMSLLC\ExtraField\ExtraValue
```

### Drop extra field

[](#drop-extra-field)

```
//this wil drop the value of the given name extra field for this model
$model->dropExtraFieldData($name) ;
```

### Drop extra field and all related data to model

[](#drop-extra-field-and-all-related-data-to-model)

`use with caution`
==================

[](#use-with-caution)

```
//this will drop the extra data field and all associated data with it
$model->dropExtraField($name);
```

### update extra field value

[](#update-extra-field-value)

sometimes you may need to update the value of the extra field, you can achive that by using this :

```
#$extra_field @param String the name of the extra field
#$updated_value @param String the new value

$model->updateExtraValue($extra_field , $updated_value);
```

### Custom models and migrations

[](#custom-models-and-migrations)

You can change the models used by specifying a class name in the `extra_model` &amp; `extra_value_model` key of the `extra-field` config file.

You can change the column name used in the extra\_values table (`model_id` by default) when using a custom migration where you changed that. In that case, simply change the `model_primary_key_attribute` key of the `extra-field` config file.

You can change the column name used in the extra\_values table (`model_class` by default) when using a custom migration where you changed that. In that case, simply change the `model_name_attribute` key of the `extra-field` config file.

### Changelog

[](#changelog)

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

Contributing
------------

[](#contributing)

You are welcome to contribute

Credits
-------

[](#credits)

- [Transport Systems](https://github.com/tmsllc)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.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

Unknown

Total

1

Last Release

1089d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9470e8330ed77d642d812eee850fbc5f76571b8b8e001dcf168ac478282ecb3c?d=identicon)[tmsllc](/maintainers/tmsllc)

---

Top Contributors

[![usmantms](https://avatars.githubusercontent.com/u/124586947?v=4)](https://github.com/usmantms "usmantms (2 commits)")[![tmsllc](https://avatars.githubusercontent.com/u/105742520?v=4)](https://github.com/tmsllc "tmsllc (1 commits)")

---

Tags

laravelextra-field

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tmsllc-laravel-extra-field/health.svg)

```
[![Health](https://phpackages.com/badges/tmsllc-laravel-extra-field/health.svg)](https://phpackages.com/packages/tmsllc-laravel-extra-field)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

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

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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