saade/laravel-uuid 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

saade/laravel-uuid

Composer 安装命令:

composer require saade/laravel-uuid

包简介

A small package for adding UUIDs to Eloquent models.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Caution

This package is a fork of saade/laravel-uuid (which is no longer maintained) to keep old projects still alive.

Laravel now has first-party support for generating UUIDs and ULIDs on Eloquent models, you should use that instead.

This package will not receive any new features or updates, only compatibility fixes.

Installation

You can install the package via composer:

composer require saade/laravel-uuid

Usage

There are 2 methods for applying automatic UUID generation to your models:

1. Applying a trait

Add the Saade\Uuid\Concerns\HasUuid trait to your model:

class Post extends Model
{
    use \Saade\Uuid\Concerns\HasUuid;
}

This will automatically assign a time-ordered UUID to the uuid column on your model. UUIDs are generated using the Str::orderedUuid() method provided by Laravel.

If you wish to change the column that is used, you can define a uuidColumn method on your model:

class Post extends Model
{
    use \Saade\Uuid\Concerns\HasUuid;

    public function uuidColumn(): string
    {
        return 'guid';
    }
}

findByUuid & findByUuidOrFail

You can use the Model::findByUuid and Model::findByUuidOrFail methods to quickly retrieve a model from it's UUID. These behave the same way as Model::find and Model::findOrFail.

2. Mass-registration in ServiceProvider

If you want to use the defaults and would like to avoid adding more traits to your model, you can mass-register your models in the boot method of a ServiceProvider.

use Saade\Uuid\Uuid;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Uuid::generateFor([
            \App\Models\Post::class,
        ]);
    }
}

Using the UUID in route definitions

If you want to use your uuid column as the default route-model binding column, you can implement the Saade\Uuid\Contracts\WithUuidRouteKey contract on your model.

This will force the HasUuid trait to use the uuid column as the return value of getRouteKeyName which Laravel uses to determine how to receive a model for implicit route-model binding.

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.

saade/laravel-uuid 适用场景与选型建议

saade/laravel-uuid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.01k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-28