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

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

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

saade/laravel-uuid

最新稳定版本:v2.0.1

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固