soysaltan/appender
Composer 安装命令:
composer require soysaltan/appender
包简介
Take your appends control in Laravel 5.6+
README 文档
README
While working with Laravel, sometimes you have to return fields that are not in your db table (https://laravel.com/docs/8.x/eloquent-serialization#appending-values-to-json). However, you may want to hide these fields that you add in some cases. In this case, you need to dominate the eloquent model.Now, you can do it easily with this package.
This package includes a Appends trait. You can use the Appends trait in any model you want. For example, if you want
to add to the User model:
class User extends Model { use HasFactory, Appends; // <--add this; ...
Installation
You can install the package via composer for Laravel 5.6+:
composer require soysaltan/appender
Usage
class User extends Model { use HasFactory, Appends; // <--add this; protected $appends = ['created_at_by_human', 'created_at_formatted'];
If you want to get your model without appends, just drop this line
User::$withoutAppends=true; // User -> your user mmodel
Note: If your model extends a custom class, you need to ensure that
your extended class has Concerns\HasAttributes trait.Otherwise this package doesn't work since
it uses Concerns\HasAttributes::getArrayableAppends method
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-14