定制 lesichkovm/laravel-advanced-model 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lesichkovm/laravel-advanced-model

Composer 安装命令:

composer require lesichkovm/laravel-advanced-model

包简介

Advanced model class for Laravel

README 文档

README

An advanced model for Laravel. Has out-of-the-box support for SnakeCase (Laravel's default), as well as for CamelCase field names, and enhanced primary key support - human friendly date based unique IDs, and UUIDs.

Background

  1. Snake case (snake_case) advanced model. This is the default Laravel's model. This model uses the foillowing fields:
id - Identity field
created_at - When was the record created
updated_at - When was the record last modified
deleted_at - When was the record deleted (soft delete)
  1. Camel case (CamelCase). Camel case is more readable and a bit shorter than snake case (more at https://en.wikipedia.org/wiki/Camel_case). This model changes the default Laravel names to:
Id - Identity field
CreatedAt - When was the record created
UpdatedAt - When was the record last modified
DeletedAt - When was the record deleted (soft delete)
  1. The default Laravel model uses only incremental primary keys. Though it works for basic use cases, this causes extra effort for deduping records on larger systems. A much better option is to use unique IDs. This class supports UUIDs, as well as more human friendly unique unique IDs (HUID).

Human-friendly Unique IDs (HUIDs)

The Human-friendly unique IDs (HUIDs) are numeric strings consisting of the date and time with a random variable length postfix. The usual length is 20, but can be increased, if more uniqueness is required. Example: 20170715081335698999

The HUIDs are less unique than UUIDs, but have more value for everyday usage:

  • They do provide enough information to uniquely identify a record in 99.99% of the user cases.
  • Being date based provides answer when the record was created.
  • Can be ordered in ascending/descending order as they are numeric
  • Unlike UUIDs are easy for humans to read, especially when separated with dashes
  • Can be further transferred to other numeric bases
{
  "human-readable-form" : "20170715-081335-698999",
  "base10" : "20170715081335698999",
  "base16" : "117ECC67F58A0F637",
  "base32" : "MDC4D43APZUIJ",
  "base36" : "498WXQXN91ET3",
  "base62" : "O225WNTn5DL",
  "base64" : "HVindzOeFOt",
  "base75" : "3hl}S8,t*rO",
  "base100" : "kh7f8dz/Y8",
  "crockford32" : "HFV66FXCA1XHQ"  
}

Installation

  • Using composer
composer require lesichkovm/laravel-advanced-model

Usage

Extend your model classes

  • Using AdvancedSnakeCaseModel
class MyModel extends \AdvancedSnakeCaseModel {
    private $useUniqueId = true;
}
  • Using AdvancedCamelCaseModel
class MyModel extends \AdvancedCamelCaseModel {
    private $useUniqueId = true;
}
  • Human-friendly Unique ID (HUID)
class MyModel extends \AdvancedSnakeCaseModel {
    private $useUniqueId = true;
}
  • Universally Unique ID (UUID)
class MyModel extends \AdvancedSnakeCaseModel {
    private $useUuid = true;
}
  • Autoincrements
class MyModel extends \AdvancedSnakeCaseModel {
    private $incrementing = true;
}

Create Model and Retrieve ID

  • Create snake case model instance and retrieve ID
$instance = new MyModel;
$instance->save();

echo $instance->id;
  • Create new camel case model instance and retrieve ID
$instance = new MyModel;
$instance->save();

echo $instance->Id;

Additional Methods

  • chunks($perChunk)

  • getConnName

  • getTableName

  • trash

  • untrash

lesichkovm/laravel-advanced-model 适用场景与选型建议

lesichkovm/laravel-advanced-model 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.72k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「model」 「laravel」 「advanced」 「lesichkov」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 lesichkovm/laravel-advanced-model 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 11
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2018-01-06