PHPackages                             stelianandrei/eloquent-custom-fields - 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. stelianandrei/eloquent-custom-fields

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

stelianandrei/eloquent-custom-fields
====================================

Add any extra fields to your Eloquent models

v0.1.0(5y ago)06MITPHPPHP ^7.3

Since Oct 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/StelianAndrei/eloquent-custom-fields)[ Packagist](https://packagist.org/packages/stelianandrei/eloquent-custom-fields)[ RSS](/packages/stelianandrei-eloquent-custom-fields/feed)WikiDiscussions main Synced yesterday

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

Eloquent Custom Fields
======================

[](#eloquent-custom-fields)

This package gives a basic way of attaching arbitrary fields to an Eloquent model. The Custom Fields are simply a collection of Eloquent models that are related to your own models via a `MorphToMany` relation.

Instalation
-----------

[](#instalation)

This package can be installed through Composer.

```
composer require stelianandrei/eloquent-custom-fields
```

Make sure you publish the required migration:

```
php artisan vendor:publish --provider="StelianAndrei\EloquentCustomFields\ServiceProvider" --tag="migrations"
```

Optionally, to publish the configuration:

```
php artisan vendor:publish --provider="StelianAndrei\EloquentCustomFields\ServiceProvider" --tag="config"
```

The CustomField model
---------------------

[](#the-customfield-model)

The model is very simple, it has just two attributes:

- `label` - (required) mainly used to identify the CustomField in a human-readable form
- `type` - (optional) what the custom field represents. This can be used to determine how to deal with that field (eg. " text", "email", "textarea") or something else as a clue for data manipulation (eg. "json", "currency" , "lat\_long").

If you need to add extra functionality to this model, just create a new model, extend the `StelianAndrei\EloquentCustomFields\CustomField` class and update the value for `field_class` in the config file ( make sure you publish it first, see above).

Usage
-----

[](#usage)

In order to allow your models to use this functionality, you need to use the `HasCustomFields` trait:

```
