marmarait / laravel-dynamic-attributes
Adds Dynamic Attributes to your Models
Installs: 30
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:libary
This package is not auto-updated.
Last update: 2025-05-11 08:50:53 UTC
README
Overview
Add Additional Fields to your Models with a key value table
Install
composer require marmarait/laravel-dynamic-attributes
Usage
-
add the Trait "HasDynamicAttributes" to your model
-
in the method "getDynamicAttributes" return an array with the dynamic attributes and their field types. Available are:
- string
- text
- int
- double
- object
- date
- time
- datetime
-
Use it as you normally would with static attributes.
Example:
If you want your Users Model to have an additional field named "country" with type string:
Add HasDynamicAttributes to your User model
Make the getDynamicAttributes method return ['country'=>'string']
Set the field by assigning the property to the model:
$user->country='Austria';
Retrieving the Property is about the same:
echo $user->country; // 'Austria'