承接 dixieio/eloquent-model-future 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dixieio/eloquent-model-future

Composer 安装命令:

composer require dixieio/eloquent-model-future

包简介

Schedule changes for Eloquent models

README 文档

README

Give your models a nice and predictable future

A package that lets you plan changes to your models in a simple manner.

Installation

Require the package via composer

composer require dixie/eloquent-model-future

Run the package migrations to create a futures table, that will hold every future of your selected models.

php artisan migrate

Schedule the command to persist future plans

$scheduler->command('future:schedule')->daily();

Usage

On your desired models use the HasFuture trait.

class User extends Model
{
    use Dixie\EloquentModelFuture\HasFuture;
}

Now you can plan out, edit and take away attribute changes, planned for the future.

Here is how you interact with your models future.

$user = User::find(1);
$nextMonth = Carbon\Carbon::now()->addMonth();

// Plan a profile change for new years eve
$user->future()->plan([
    'bio' => 'Happy developer time. Wooh!',
    'mood' => 'excited',
])->for($nextMonth);

// Does our user have any scheduled plans for next month?
$user->future()->anyPlansFor($nextMonth); // true

// How does our user look in the future
$user->future()->see($newYearsEve);
User {
  'attributes': {
      'id': 1,
      'name': 'John Doe',
      'bio': 'Happy developer time. Wooh!',
      'mood': 'excited',
      [...]
  }
}

// You can commit to the changes by future plans after you've seen them
// ... this will fill the `committed` column with todays date
$user->future()->see($newYearsEve)->commit(); // true

// Access all future plans for the given day
$futurePlans = $user->future()->getPlansFor(Carbon $date)
FutureCollection {
    Future {
        'attributes' => [
            'bio' => 'Happy [...]',
            'mood' => 'excited',
        ]
    }
}

// There are some helper methods that come with the FutureCollection
$futurePlans->original();   // Original user state. Returns a user instance.

$futurePlans->result();     // How the user will look when collection is applied to user.
$futurePlans->resultDiff()  // Shows which attributes has changed 
                            // and what the values would be before and after

API Reference

Class#methodName Arguments Returns Note
Future#untilDate Carbon Eloquent\Builder Query only futures scheduled between date('now') and the given date. This is an Eloquent scope.
Future#uncommitted - Eloquent\Builder Query only uncommitted futures. This is an Eloquent scope.
Future#committed - Eloquent\Builder Query only committed futures. This is an Eloquent scope.
Future#futureable - MorphTo This is a standard Eloquent polymorphic relationship. (Inverse of HasFuture#futures)
FutureCollection#original - Model Gets the model back with no data changed.
FutureCollection#result - Model Gets the model back with all the future data filled. It is not saved
FutureCollection#resultDiff - Support\Collection Gets a list of all fields that would change, with both before and after
FuturePlanner#plan array FuturePlanner Set the attributes which should be persisted later.
FuturePlanner#for Carbon Future Set the date for when the attributes should be persisted.
FuturePlanner#see Carbon Model See the final result of a model for a given date.
FuturePlanner#getPlans - FutureCollection Get all future plans for a model.
FuturePlanner#getPlansFor Carbon FutureCollection Get all future plans for a model for the given day.
FuturePlanner#getPlansUntil Carbon FutureCollection Get all future plans for a model, between now and the given date.
FuturePlanner#hasAnyPlans - boolean See if model has any future plans at all.
FuturePlanner#hasAnyPlansFor Carbon boolean See if model has any future plans for the given date.
FuturePlanner#hasAnyPlansUntil Carbon boolean See if model has any future plans between now and the given date.
HasFuture#futures() - MorphMany This is a standard Eloquent polymorphic relationship
HasFuture#uncommittedFutures - MorphMany Same as futures but filtered to only include uncommitted futures
HasFuture#commit - boolean This is a wrapper around $model->save() but it also sets the committed flag to Carbon::now()
Future#forDate Carbon Eloquent\Builder Query only futures scheduled for the given day. This is an Eloquent scope.

dixieio/eloquent-model-future 适用场景与选型建议

dixieio/eloquent-model-future 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dixieio/eloquent-model-future 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dixieio/eloquent-model-future 我们能提供哪些服务?
定制开发 / 二次开发

基于 dixieio/eloquent-model-future 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 43
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2017-05-15