marmarait/laravel-dynamic-attributes
Composer 安装命令:
composer require marmarait/laravel-dynamic-attributes
包简介
Adds Dynamic Attributes to your Models
README 文档
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'
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-31