PHPackages                             asseco-voice/laravel-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. asseco-voice/laravel-custom-fields

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

asseco-voice/laravel-custom-fields
==================================

Laravel support for custom fields

v3.5.4(7mo ago)507.7k↓100%10[4 PRs](https://github.com/asseco-voice/laravel-custom-fields/pulls)MITPHPPHP ^8.1CI passing

Since Feb 10Pushed 7mo ago6 watchersCompare

[ Source](https://github.com/asseco-voice/laravel-custom-fields)[ Packagist](https://packagist.org/packages/asseco-voice/laravel-custom-fields)[ RSS](/packages/asseco-voice-laravel-custom-fields/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (59)Used By (0)

[![](https://github.com/asseco-voice/art/raw/main/evil_logo.png)](https://see.asseco.com)

Custom fields
=============

[](#custom-fields)

Purpose of this repository is to provide custom field support for any Laravel model.

**Custom field** can be any field with which you wish to extend your model providing a highly flexible model for additional fields, without the need to add new attributes to a DB model.

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

[](#installation)

Require the package with `composer require asseco-voice/laravel-custom-fields`. Service provider will be registered automatically.

Setup
-----

[](#setup)

In order to use this repository the following must be done:

1. Each model which requires custom field support MUST use `Customizable` trait.
2. Run `php artisan migrate` to migrate package tables
3. Run `php artisan db:seed --class="Asseco\CustomFields\Database\Seeders\PlainTypeSeeder"`to seed mandatory data only.
4. You may include `CustomFieldPackageSeeder` within your `DatabaseSeeder`seeders and have it seed mandatory data in all environments or seed all other dummy data in non-production environments.

ERD
---

[](#erd)

[![graph](erd.png)](erd.png)

Custom field types breakdown
============================

[](#custom-field-types-breakdown)

A single custom field can assume the form of one of three different types of custom fields, all of which are a polymorphic relation to custom fields table.

#### Plain type

[](#plain-type)

Plain types are a standard single-value properties like int/string/date etc. Be sure to seed the mandatory data before you go and use the package as these fields map directly to custom field value attributes depending on their type.

I.e. if you say that custom field is of a plain string value, its value will be written in the string column of a custom field values table.

#### Remote type

[](#remote-type)

If you'd like to fetch custom fields from some arbitrary endpoint, you can use remote type. Remote type has standard URL/method/headers/body attributes so that your request can be executed successfully.

Using remote type custom fields require you to define which plain types are you ultimately returning so that package knows how to map the values to their attribute columns.

#### Selection type

[](#selection-type)

Selection types provide a set of predefined values from which you can select one or many.

Selection types also require you to define which plain types are you ultimately returning so that package knows how to map the values to their attribute columns.

Defining custom fields
======================

[](#defining-custom-fields)

Once all the mandatory data is seeded you can start defining custom fields. You can do so in several ways:

- through `/api/custom-fields` CRUD controller endpoints if you wish to provide all the fields necessary for defining a single custom field
- through helper endpoints (where `plain_type` parameter is one of plain types defined in the DB. Using invalid parameter will result in 404):
    - `/api/custom-field/plain/{plain_type}` - for creating plain type custom-field.
    - `/api/custom-field/selection/{plain_type}` - for creating selection type custom-field.
    - `/api/custom-field/remote` - for creating remote type custom-field. Omitting the `plain_type` attribute and hard-coding to string currently.
- with Tinker in the console

Once a custom field is defined, you can add a value for a particular model against that custom field.

I.e. if you have a `Contact` model, instead of adding a `car` attribute to `contacts` table, you can define a string plain type custom field `car` for `Contact` model. At that point, no `Contact` has a value assigned to it. Only when custom field is defined can you go and say that for example `Contact` with ID 5 has a Volvo.

Custom field attributes
-----------------------

[](#custom-field-attributes)

- `name` - unique name of the custom field.
- `label` - user-friendly name of a custom field.
- `placeholder` - placeholder.
- `selectable` - polymorphic attribute (`_type`, `_id`) which can assume [one of 3 available types](#custom-field-types-breakdown).
- `model` - namespace of the model for which the custom field will be applicable.
- `required` - is a custom field required. Default `false`.
- `validation_id` - relation to [validation field](#validation).
- `group` &amp; `order` - nullable front-end friendly strings to provide grouping if needed.

Plain type attributes
---------------------

[](#plain-type-attributes)

Plain types have only `name` defined. These map to `custom_field_values` table attributes so be sure to seed mandatory types.

This is done because of data validation on DB level as well as faster value searching.

I.e. one of plain types is `string`, and looking at `custom_field_values` migration you'll notice that there is a `string` attribute as well.

Selection type attributes
-------------------------

[](#selection-type-attributes)

Selection types have two tables: `selection_types` and `selection_values`.

Selection types have defined `plain_type_id` which is a plain type that selection values should be mapped to. It is not possible to have plain type values of mixed types. There is also a `multiselect` boolean which should indicate to front-end whether it is possible to select only one or multiple values from the list.

Values table holds all values which should for a particular selection field be available to pick. There are standard `label` and `value` fields for selections as well as `preselect` bool which should indicate to the front-end whether the value should be preselected (kinda like placeholder for selection).

Remote type attributes
----------------------

[](#remote-type-attributes)

Remote types have standard `url, method, body, headers` attributes to define an endpoint from where the fields should be fetched.

You can resolve the values on `/api/custom-field/remote/{remote_type}/resolve` endpoint.

While resolving the values from an endpoint, there is also a possibility to provide `mappings`. If set to `null`the response will be returned as-is. Otherwise, there is a possibility to provide mappings in `localKey => remoteKey` which means that response will be remapped to JSON provided in the `mappings` field.

I.e.

```
Response:
{
    "remote_user": "foo"
}

Mapping:
{
    "user": "remote_user"
}

Result:
{
    "user": "foo"
}

```

Using custom fields
===================

[](#using-custom-fields)

Once you have custom fields defined, you can start assigning values to models. You can do so by hitting the `/api/custom-field/values` endpoint. Be sure to provide the right value in the request (i.e. for string field provide a `string` attribute in the payload) because otherwise the package will reject the value as invalid.

During value storing, aside from value type check, you can also add [regex validation](#validation) to a custom field which will be validated at that point as well.

Validation
==========

[](#validation)

You can provide regex validation for a custom field in a `/pattern/` or `pattern` format. You can assign it a `name` if needed for front-end purposes, as well as setting `generic` bool option which is also a front-end helper designed to filter out most common used validations. You can set those to `true` and then return only `true` ones in front-end dropdown.

Relationship
============

[](#relationship)

Providing a parent-child M:M relationship on custom fields.

Form
====

[](#form)

Form is a helper model for our specific [form.io](https://www.form.io/) use case.

When creating a form, its definition will be parsed and will automatically relate custom fields used on an M:M pivot table. Parsing works on [form.io](https://www.form.io/)definition only.

If you want to make your own parser, you can publish the config file and replace `Form` model implementation with your form. Extend the parent model and override `relateCustomFieldsFromDefinition()` function.

Extending the package
=====================

[](#extending-the-package)

Publishing the configuration will enable you to change package models as well as controlling how migrations behave. If extending the model, make sure you're extending the original model in your implementation.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance65

Regular maintenance activity

Popularity35

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 65.2% 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 ~34 days

Recently: every ~14 days

Total

51

Last Release

210d ago

Major Versions

v0.5.1 → v1.0.02021-08-11

v1.4.0 → v2.0.02022-05-05

v2.3.1 → v3.0.02023-08-08

PHP version history (4 changes)v0.1.0PHP ^7.4

v0.2.0PHP ^7.4 || ^8.0

v2.0.0PHP ^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d61de45741b74e7d4a9ee5778160cf54ae5e94a615ae1a6f72b6d1e5fae68d12?d=identicon)[Norgul](/maintainers/Norgul)

---

Top Contributors

[![Norgul](https://avatars.githubusercontent.com/u/11718157?v=4)](https://github.com/Norgul "Norgul (105 commits)")[![josip-milotic](https://avatars.githubusercontent.com/u/42002911?v=4)](https://github.com/josip-milotic "josip-milotic (15 commits)")[![ngaspari](https://avatars.githubusercontent.com/u/33628128?v=4)](https://github.com/ngaspari "ngaspari (15 commits)")[![assefvisic](https://avatars.githubusercontent.com/u/60132037?v=4)](https://github.com/assefvisic "assefvisic (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![AkronimBlack](https://avatars.githubusercontent.com/u/39061674?v=4)](https://github.com/AkronimBlack "AkronimBlack (4 commits)")[![DaveXo9](https://avatars.githubusercontent.com/u/85836822?v=4)](https://github.com/DaveXo9 "DaveXo9 (2 commits)")[![marijo-pavlov](https://avatars.githubusercontent.com/u/12993093?v=4)](https://github.com/marijo-pavlov "marijo-pavlov (1 commits)")

---

Tags

databaselaravellaravel-8-packagelaravel-frameworklaravel-packagemicroservicemicroservicesphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asseco-voice-laravel-custom-fields/health.svg)

```
[![Health](https://phpackages.com/badges/asseco-voice-laravel-custom-fields/health.svg)](https://phpackages.com/packages/asseco-voice-laravel-custom-fields)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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