Download the PHP package drhtoo/laravel-metafield without Composer
On this page you can find all versions of the php package drhtoo/laravel-metafield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-metafield
Laravel Metafield Package
The Laravel Metafield package allows you to add custom metafields to your Laravel Eloquent models. This is useful when you need to store additional data about a model beyond its basic attributes.
Installation
To install the package, you can simply run the following Composer command:
Publishing Config and Migration (Optional)
After you've installed the package, you can optinally publish the package's config and migrations to your Laravel application. You can do this by running the following command:
Once the migrations have been published, you can run them by using the following command:
Usage
To start using the Laravel Metafield package, you'll need to add the HasMeta trait to any Eloquent models that you want to have metafields. Here's an example:
Now, you can use related meta fields by using relationship metas
MetaFields Property
To use meta fields as a model attribute, you have to add $metaFields property to your model. It is a protected property of array type which is the default values keyed by the field/key.
Attribute Casting
You can also cast the metafield as in attributes of Eloquent/Models.
Working with Livewire Component
This package is well compatible with Livewire component and directly bind to wire:model attribute. To be able to livewire component find the metafield attributes, you need to append the fields to model attributes.
Working with Spatie's Laravel-translatable Package
Laravel Meta Field works well with spatie/laravel-translatable package and you just simply add array item of meta field to $translatable property of your model and use setAttribute method of HasMeta trait insteadof Translatable.
That's all. Have fun.