Download the PHP package faizansf/laravel-metafields without Composer

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

Laravel Metafields

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

The Laravel Metafields package is a versatile and powerful tool designed for Laravel developers who need to extend their models with metafield functionality. This package enables you to effortlessly attach additional custom fields (metafields) to any Eloquent model in your Laravel application, providing a seamless way to enhance your models with extra data without altering your database schema.

Use Cases:

This package is ideal for projects that require additional data storage like CMS, e-commerce platforms, and custom CRM systems. It's particularly useful in scenarios where the database schema needs to remain unchanged while still allowing for data extension.

Installation

You can install the package via composer:

You can publish and run the migrations with:

Note:
Before running the migrations make sure you have set the correct configuration

You can publish the config file with:

Configuration

Integrating in Model

Integrate the Metafiedable contract and the HasMetafields trait into your model

Usage

To set a metafield, use string or string backed enum key and value as below:

To get metafield value use:

You can also provide a default value when getting a metafield

Note:
A default value is not persisted in the database and is just returned whenever the actual value is null

Similarly, metafields can be deleted as follows:

Cache

Caching is enabled by default, but can be disabled in your metafields.php configuration file. To control caching behavior in your model class, add the $shouldCacheMetafields property. Setting this property in your model will override the default caching configuration. Additionally, you can specify a custom time-to-live (TTL) for the cache by adding the $ttl property to your model, allowing for fine-tuned cache duration control.


In the metafields.php config file

Or in your model class


You can retrieve a non-cached version of the data by using the withoutCache() method. This method provides a straightforward way to bypass caching for a single call, ensuring you get the most up-to-date data.

Serialization

The package includes StandardValueSerializer, DirectValueSerializer and JsonValueSerializer classes. You can choose a default serializer for all fields in the metafields.php configuration file. Additionally, you can define a $metafieldSerializers array inside your model, or you can implement a protected registerSerializers() method in your model to override the default serialization behavior. The registerSerializers() method will then use mapSerializer() method provided by HasMetafields trait to register the serializers. Any custom serializer class you add must implement the FaizanSf\LaravelMetafields\Contracts\ValueSerializer interface.


And then in your model

Alternatively, you can also define $metafieldSerializers property directly into your model

Note:
Due to PHP's restriction where enums can't be used as array keys, we need to utilize the enum values for mapping serializers.


In situations where you already possess a string value that doesn't require serialization, the DirectValueSerializer can be used. This allows you to bypass the usual serialization process, streamlining the handling of such pre-formatted or non-serializable values.

Testing

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-metafields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.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 faizansf/laravel-metafields contains the following files

Loading the files please wait ....