Michael-Rubel / laravel-model-mapper
3.4.3
2023-01-19 10:55 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.9
Requires (Dev)
- brianium/paratest: ^6.3
- laravel/pint: ^1.0
- mockery/mockery: ^1.4.4
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^9.5
- roave/backward-compatibility-check: ^7.0|^8.0
This package is auto-updated.
Last update: 2023-01-19 10:57:04 UTC
README
Laravel Loop Functions
该包提供了一组用于遍历数据的方法。
该包需要PHP 8或更高版本和Laravel 9或更高版本。
#StandWithUkraine
安装
使用composer安装此包
composer require michael-rubel/laravel-loop-functions
使用方法
use LoopFunctions;
将Eloquent模型属性分配给类属性
$this->propertiesFrom($model);
将数组键值分配给类属性
$this->propertiesFrom($array);
如果需要使用动态属性,调整配置中的dynamic_properties
键,如果您的类尚未实现get/set
魔术方法,请添加以下特质:
use WithDynamicProperties;
注意:如果您使用Livewire组件,它已经在内部有类似的定义。
转储类属性
$this->dumpProperties();
忽略属性名称
默认情况下,该包忽略id
和password
属性以避免在Livewire/auth组件中发生冲突。您可以通过编辑配置来自定义忽略列表。
php artisan vendor:publish --tag="loop-functions-config"
日志记录
在赋值失败的情况下(例如,类型不兼容),函数不会抛出异常,但会记录此类事件。您可以在配置中禁用异常日志记录,如果需要的话。
测试
composer test
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。