Download the PHP package asseco-voice/laravel-custom-fields without Composer

On this page you can find all versions of the php package asseco-voice/laravel-custom-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-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

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

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

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 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

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 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

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

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

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 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 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.

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 to a custom field which will be validated at that point as well.

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

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

Form

Form is a helper model for our specific 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 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

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.


All versions of laravel-custom-fields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^10.0
asseco-voice/laravel-common Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package asseco-voice/laravel-custom-fields contains the following files

Loading the files please wait ...