Download the PHP package hxm/extrafield without Composer
On this page you can find all versions of the php package hxm/extrafield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hxm/extrafield
More information about hxm/extrafield
Files in hxm/extrafield
Package extrafield
Short Description Extra fields package, simple, extensible and powerful extra fields implementation for Laravel.
License MIT
Informations about the package extrafield
HoanXuanMai — hxm/extrafield
This is a respository developed to add extra fields to models on Laravel projects.The hxm/extrafield package provides a simple and flexible way to add custom fields to your Laravel Eloquent models. With this package, you can easily define additional fields to store any type of data that you need, such as metadata, settings, or preferences. The extra fields are seamlessly integrated with the model attributes, allowing you to access and modify them using the same syntax as regular attributes. Moreover, the package offers convenient features such as default values, validation rules, and automatic casting to various data types. Whether you are building a small application or a large-scale system, hxm/extrafield can help you extend your models with ease and efficiency.
Instead of you needing to create additional columns on the existing database structure, you can simply use this respository.
Installation
Use [Composer] to install the package:
Use [Migration] to creating all tables:
you can also skip the migration by adding the following code in your AppServiceProvider
.
Basic Usage
To be able to add extra fields to the Model we just need to implement the Interfaces into the Model Class. It comes with a built-in Trait so you can easily use it.
HXM\ExtraField\Contracts\CanMakeExtraFieldInterface
The Model Class will share the same Additional Fields across instances
You will have a Trait dedicated to it:
HXM\ExtraField\Traits\HasExtraFieldByInstance
.
HXM\ExtraField\Contracts\CanMakeExtraFieldByInstanceInterface
: The Model class will have its own Extra Fields on each instance, to be used as an intermediate Model class.
You will have a Trait dedicated to it:
HXM\ExtraField\Traits\HasExtraFieldByInstance
.
HXM\ExtraField\Contracts\CanMakeExtraFieldByInstanceInterface
: used when there is a parent Model class, contact the current class, to be able to get the Extra Fields option depending on the child Model class
do not forget to add function public function getExtraFieldTargetTypeInstance(): CanMakeExtraFieldInterface
, it will help the system know which relation you are using to access Extra Fields
Saving Extra Fields
Now, to add Extra Fields to the database, you just need to use actions directly on the controller in your admin
Don't worry, because there is a built-in validation system before the data is saved to the database.
Save Extra Field Values
HXM\ExtraField\Contracts\CanAccessExtraFieldValueInterface
This contract stipulates on the Model class, where it can add values on the previously added list of Extra Fields
Attached to it are some pre-built Traits to ensure the structure: HXM\ExtraField\Traits\HasExtraFieldValue
, HXM\ExtraField\Traits\AutoValidationAndSaveExtraFieldValue
HasExtraFieldValue
there will be a 1-n relational function added to the Model, called extraValues()
AutoValidationAndSaveExtraFieldValue
You use it so that the value is automatically saved for the Model class when you create or update it. Remember, it will come with a validation set before you can save the current Model. you may not use it, saving the value will be manually inserted another piece of code into your Controller
if you want to save it yourself, then remove the Trait from the Model class. the following code will help you to save manually by yourself:
Advanced
This repository is used with the hxm/enum package. So you can create your own EnumInstances for many structures on your system.
first, don't forget to publish the package's config file via the command:
This Enum class must implement from Interface: HXM\ExtraField\Contracts\ExtraFieldTypeEnumInterface
, otherwise you will get an error when integrating it into the system
In addition, you can also customize the value handler when saving and retrieving from the database
This Enum class must implement from Interface: HXM\ExtraField\Contracts\ExtraValueProcessValueInterface
, otherwise you will get an error when integrating it into the system
License
Laravel User Agent is licensed under The MIT License (MIT).
Donations
Paypal