Download the PHP package aurorawebsoftware/flexyfield without Composer
On this page you can find all versions of the php package aurorawebsoftware/flexyfield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aurorawebsoftware/flexyfield
More information about aurorawebsoftware/flexyfield
Files in aurorawebsoftware/flexyfield
Package flexyfield
Short Description Laravel Models are now Uber Flexy!
License MIT
Homepage https://github.com/aurorawebsoftware/flexyfield
Informations about the package flexyfield
FlexyField - Dynamic Model Fields for Laravel
FlexyField is a dynamic fields package for Laravel, allowing developers to define flexible and customizable fields on models without needing to change the database schema.
It enables on-the-fly definition of fields, field types, validation, and value assignment, providing the perfect solution for projects requiring flexible content structures.
Key Features
- Dynamically add fields to any Eloquent model.
- Supports field types: String, Integer, Decimal, Date, Boolean and DateTime.
- Field-level validation using Laravel’s validation rules.
- Query models by flexible field values using Elequent's native methods.
- Supports multiple field types and data storage through a pivot view.
- Fully integrable with Laravel's native model structure.
Installation
To install the package via Composer, run:
After installing, run the provided migrations to create the necessary tables:
Database Structure
The package creates two main tables and one view:
ff_shapes
: Holds the shapes definitions of fields with validation rules and validation messagesff_values
: Stores the actual values assigned to models' flexy fields.ff_values_pivot_view
: Views all values as a pivot table
Quick Start
Adding Flexy Fields to a Model
To start using Flexy fields, simply include the Flexy
trait and implement the FlexyModelContract
in your model.
This enables the model to support dynamically assigned fields.
Setting and Retrieving Flexy Fields
Once the model is set up, you can define and assign flexy fields to it. Fields are assigned through the flexy
attribute.
Defining Model Shapes for Validation
A shape is a field definition with a type and validation rules. Each Model can have one shape.
You can define shapes dynamically with setFlexyShape()
for fields to apply validation.
This ensures that when saving the color
field, it must be a required, and the size
field must be a number greater than or equal to 20.
all available validation rules: https://laravel.com/docs/11.x/validation#available-validation-rules
To retrive and delete a model shape
Saving a Model with Validation
After defining shapes with validation, saving a model with invalid data will throw a ValidationException
.
Advanced Usage
Querying Models by Dynamic Fields
FlexyField allows you to query models based on their flexy field values. Here's an example of how to filter models using their Flexy fields:
Dynamic Validation
Flexy fields can be validated using the shapes you define. For example, you can set validation rules like:
If a user tries to save invalid data, Laravel's native validation system kicks in and prevents the save:
Using Dates and Datetimes
FlexyField supports handling date
and datetime
field types.
Dynamic Field Sorting
FlexyField allows you to specify a sorting order for fields using the sort
parameter:
This controls how fields are ordered when retrieved or displayed.
Configuration
You can configure the package to use different database drivers (e.g., MySQL or PostgreSQL) for the flexy field pivot table.
Contribution
Feel free to contribute to the development of FlexyField by submitting a pull request or opening an issue. Contributions are always welcome to enhance this package.
Running Tests
Before submitting any changes, make sure to run the tests to ensure everything is working as expected:
You can run the tests provided using Pest to ensure everything is working as expected.
Code Style
Static Analyze
License
The FlexyField package is open-sourced software licensed under the MIT License.
All versions of flexyfield with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0