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

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

Cover Image

Laravel Package for Managing Custom Fields for Each Model

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This Laravel package allows you to dynamically add custom fields to any model in your application. It supports storing custom fields as polymorphic relationships and offers dynamic loading of custom field responses directly into the model’s attributes, including support for default values.

Installation

You can install the package via composer:

You can publish and run the migrations with:

You can publish the config file with:

This is the contents of the published config file:

Usage

Configuration

You can customize the table names and field prefixes by publishing the configuration file and making changes to it.

Overriding Models

You may want to extend or override the CustomField or CustomFieldResponse models provided by this package. To do this, you can publish the configuration file and update it to use your own custom models.

Trait for Managing Custom Fields

To use this package, add the HasCustomFields trait to any model where you want to allow custom fields. This trait allows you to easily add, update, and retrieve custom fields and their responses.

Now you can add custom fields for this model, save responses, and retrieve them as attributes with a configurable prefix.

Add Custom Fields

You can create a custom field for the model like this:

Below is a list of fields used in the CustomField model and their purposes:

Save Custom Field Responses

You can save responses for custom fields like this:

The saveCustomFieldResponses method is used to either insert or update responses for custom fields tied to a specific model record. This ensures that if a response already exists for a given field on a record, it will be updated, and if not, a new response will be inserted.

You may pass validate : false as a second parameter to bypass the validations which is ON by default.

Loading Custom Fields with Responses

You can simply load the custom field responses by calling the model with relationships like this:

This will retrieve all Post records along with their custom field responses and the related custom fields.

You can also fetch a single post with its custom fields and responses like this:

Using Helper Function

For a single Post, you can use the helper function getCustomFieldsWithResponses() to load the custom fields and their responses:

This will load the custom fields and their associated responses for the given post instance, making them easily accessible.

Using the LoadCustomFields Trait

Alternatively, you can use our second trait, LoadCustomFields, which automatically attaches the custom fields and their responses as attributes to each model instance.

Custom field keys will be prefixed by a string that you can configure in the configuration file. By default, the prefix is cf_, but you can change it in the config.

Using the LoadCustomFields trait, you can access custom fields directly as attributes:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-custom-fields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^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 spykapp/laravel-custom-fields contains the following files

Loading the files please wait ....