Download the PHP package informatica_mobius/laravel-custom-fields without Composer

On this page you can find all versions of the php package informatica_mobius/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

Laravel11 Custom Fields

Laravel Custom Fields is a package that allows you to add custom fields to any Laravel11 model and associate responses to those fields with other models.

Installation

To get started, add the informatica_mobius/laravel-custom-fields package to your composer.json file and update your dependencies:

Publish the migration:

Run the migration:

You can customize the table names using configuration options. More on that later.

An example - Survey App

For the purposes of the documentation, lets use the example of a Survey building app. Administrators might use a backend to create Surveys full of questions and end users might then fill out those surveys, generating SurveyResponses.

Preparing your models

Adding custom fields

To add basic custom field support, simply add the HasCustomFields trait at the top of your model:

Adding custom field responses

Next, we add support to store custom field responses. We'll simply pull in the HasCustomFieldResponses trait at the top of our SurveyResponse model.

Basic usage

Creating fields

You can add a field to a model like this:

Each field can contain the following: (More on these later)

title : The title / question of your custom field. description : The description of your field. Useful for providing more context to user filling out fields. type : The type of field you're creating. Available types are outlined in the next section. required : A boolean representing whether a field is required or not. answers : An array of acceptable values for fields that have user-selection.

Creating field responses

To store a response on a field, you can do this:

Retrieving fields

To retrieve custom fields, use the customFields relation:

Retrieving field responses

To retrieve the responses on a field, use the responses() relation:

Custom field types

Custom fields may be any of 5 types:

In general, these field types correspond to their respective HTML elements. In the future we may provide front-end scaffolding for these fields, but for now, that's up to you.

*The radio and select field types require you to fill the answers property on the field. This is a simple array of strings, which are valid responses for the field. For example:

Validating responses

Validation helpers

In most cases, you'll want to validate responses to your custom fields before saving them. You can do so by calling the validateCustomFields() function on your model:

You can also pass in a Request object:

When using a Request object, the input key should be an array of values

Implicit validation rules

The 5 supported field types described above automatically have the following validation rules applied to them:

Important: when using checkboxes, it is important you POST unchecked boxes as well, otherwise your response data may be incomplete.

Required fields

Because of how common they are, required fields have native support in this package. To mark a field as required, simply set required to true when creating a custom field.

Custom validation rules

Along with the built in validation rules, you can apply your own rules to the any custom field. For example, if you wanted to validate a field was an integer between 1 and 10, you could do the following:

Remember, the validation_rules supports any of the available validation rules in Laravel.

Validation Rule Sets

-> nah? In some cases, it's easier and more practical to define validation rules sets. For example, in our Survey app, if we wanted to offer a

Saving Responses

To store responses to custom fields, just call saveCustomFields() and pass in an array of values

The saveCustomFields function can take in a Request or array.

If you're submitting a form request, you can easily:

Querying responses

You can query for responses on any field by using the WhereCustomField() scope. The function takes in the field object and the value you're looking for. To learn more about query scopes visit this link.

For example, if you wanted to find all SurveyResponses with a large T-shirt size, perform the following query:

Ordering

You can change the order of custom fields on a model by using the order function. Pass in either an array or Collection of ids. The index position of the field represent the order position of it.

You can also manually change the value of the order column:

By default, custom fields are returned in ascending order when retrieved via the relation:

Configuration

To publish the configuration file, run the following command:

The configuration file should now be published in config/custom-fields.php. The available options and their usage are explained inside the published file.

License

Released under the MIT license. See LICENSE for more information.


All versions of laravel-custom-fields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^11.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 informatica_mobius/laravel-custom-fields contains the following files

Loading the files please wait ....