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

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

marslankhalid/laravel-extra-field
=================================

A package to enable assigning extra fields to Eloquent Models

1.0.1(1mo ago)08↓100%MITPHPPHP ^8.0|^8.1|^8.2

Since May 19Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (4)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

43

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~1069 days

Total

2

Last Release

48d ago

PHP version history (2 changes)1.0.0PHP ^8.0

1.0.1PHP ^8.0|^8.1|^8.2

### Community

Maintainers

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

---

Top Contributors

[![DevMArsalan-ctrl](https://avatars.githubusercontent.com/u/263907356?v=4)](https://github.com/DevMArsalan-ctrl "DevMArsalan-ctrl (4 commits)")[![marslankhalid](https://avatars.githubusercontent.com/u/16500135?v=4)](https://github.com/marslankhalid "marslankhalid (2 commits)")[![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/marslankhalid-laravel-extra-field/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

3.0k54.1M11.0k](/packages/illuminate-database)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8733.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)

PHPackages © 2026

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