ngoubaux/delatbabel-fluents
最新稳定版本:v11.0
Composer 安装命令:
composer require ngoubaux/delatbabel-fluents
包简介
Convert Eloquent Model objects to and from Fluent objects.
README 文档
README
Laravel extension to convert to/from Fluent objects.
Rationale
The Laravel Fluent object is one of the most under-rated and under-utilized components of the framework. Essentially a free-standing object, it allows you to access an array of attributes as an object rather than as an array.
example:
Instead of using an array like this:
$myArray = []; $myArray['first'] = 'one'; $myArray['second'] = 'two; echo $myArray['first']; // prints "one"
Use fluent object like this:
$myObject = new Fluent(); $myObject->first = 'one'; $myObject->second = 'two'; echo $myObject->first; // prints "one"
Until now, however, there has been no standard straightforwards way to convert an Eloquent Model object into a Fluent object. There is a toArray() function on a Model object but no equivalent toFluent() function.
This component adds such functions using a trait that can be applied to any model object.
Note that several other of Laravel's internal classes can also have this trait applied,
as long as they store their data in an internal attributes array this trait should
work.
Usage
Model Fill From Fluent Object
use Delatbabel\Fluents\Fluents; class User extends Eloquent { use Fluents; } $myFluent = new Fluent(); $myFluent->first = 'one'; $myUser = new User(); $myUser->fromFluent($myFluent);
Model Convert From Fluent Object
use Delatbabel\Fluents\Fluents; class User extends Eloquent { use Fluents; } $myUser = User->find(1); $myFluent = User->toFluent();
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-30