承接 andresuntoro/softexpires 相关项目开发

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

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

andresuntoro/softexpires

最新稳定版本:v1.1

Composer 安装命令:

composer require andresuntoro/softexpires

包简介

A trait package to add soft expires feature to eloquent laravel/lumen

README 文档

README

A simple trait package for eloquent laravel/lumen which is useful for handling expired data automatically.

Installation

Require this package, with Composer, in the root directory of your project. Composer 2 is a must!.

composer require andresuntoro/softexpires

Configuration

You should add the "expired_at" column to your database table.

Usage

Here you can see an example of you may use this package. Just add AndreSuntoro\Database\Eloquent\SoftExpires; to your model and use it. You can combine with others trait too, for the example: SoftDeletes.

<?php
namespace App\Models;

use AndreSuntoro\Database\Eloquent\SoftExpires;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Transaction extends Model {
    use SoftDeletes, SoftExpires;

    // ..

}

You can define when the data is considered expired. The data will not appear from the query results if it has reached the specified time limit, the default is 300 seconds(5 Mins).

<?php
namespace App\Models;

use AndreSuntoro\Database\Eloquent\SoftExpires;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Transaction extends Model {
    use SoftDeletes, SoftExpires;

    // in seconds, example 600 seconds (10 mins). The default is 300 seconds if not specified.
    const EXPIRED_AT_VALUE = 600; 

}

You can define your custom expired column if you don't use the default (expired_at).

<?php
namespace App\Models;

use AndreSuntoro\Database\Eloquent\SoftExpires;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Transaction extends Model {
    use SoftDeletes, SoftExpires;

    const EXPIRED_AT = 'my_expired_at';

}

Here you can see examples of using the available methods.

use App\Models\Transaction;

// As noted above, soft expired models will automatically be excluded from query results. However, you may force soft expired models to be included in a query's results by calling the withExpired method on the query:
$trx = Transaction::withExpired()->get();

// The onlyExpired method will retrieve only soft deleted models:
$trx = Transaction::onlyExpired()->get();

// To restore a soft expired model, you may call the reset method on a model instance. The restore method will set the model's expired_at column to null or your specified datetime:
$trx = Transaction::find(1);
$trx->reset(); // Set to null
$trx->reset(date('Y-m-d H:i:s')); // Set to your desired date time value

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-30