承接 awtechs/laravel-public-ulid 相关项目开发

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

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

awtechs/laravel-public-ulid

最新稳定版本:v1.0.1

Composer 安装命令:

composer require awtechs/laravel-public-ulid

包简介

Binary ULID public identifiers for Laravel models

README 文档

README

Binary ULID public identifiers for Laravel models.

This package stores ULIDs in a compact 16-byte binary column, casts them to their canonical Base32 string form, and makes them suitable for public routes.

Requirements

  • PHP 8.2+
  • Laravel 12+
  • symfony/uid 7+

Installation

composer require awtechs/laravel-public-ulid

Quick Start

  1. Add the schema macro in a migration:
Schema::table('users', function (Blueprint $table) {
    $table->publicUlid();
});
  1. Add the trait to your model:
use Awtechs\PublicUlid\Concerns\HasPublicUlid;

final class User extends Model
{
    use HasPublicUlid;
}

Now public_id is automatically created as a ULID, stored as binary, and used for route model binding.

How It Works

  • Binary storage: public_id is a 16-byte binary column.
  • Cast: public_id is cast to a Base32 ULID string via BinaryUlidCast.
  • Auto-generation: on creating, if public_id is missing, a ULID is set.
  • Route key: getRouteKeyName() returns public_id.

Casting

If you need to customize or reuse the cast directly:

use Awtechs\PublicUlid\Casts\BinaryUlidCast;

protected $casts = [
    'public_id' => BinaryUlidCast::class,
];

Validation Rule

use Awtechs\PublicUlid\Rules\ValidUlid;

request()->validate([
    'public_id' => ['required', new ValidUlid()],
]);

Console Command

Decode ULID details from the CLI:

php artisan ulid:inspect 01HZX9J4P7VWH2T0R0X6Q8N5E3

Testing Helpers

use Awtechs\PublicUlid\Testing\AssertsUlids;
use Awtechs\PublicUlid\Testing\GeneratesUlids;

final class ExampleTest extends TestCase
{
    use AssertsUlids;
    use GeneratesUlids;

    public function test_ulid_helpers(): void
    {
        $ulid = $this->newUlid();
        $this->assertValidUlid($ulid);
    }
}

Add the Faker provider if you need ULIDs in factories:

use Awtechs\PublicUlid\Testing\Faker\PublicUlidProvider;

$faker->addProvider(new PublicUlidProvider($faker));
$faker->ulid();

Notes

  • The column name is public_id by design.
  • ULIDs are stored in binary, but are exposed as Base32 strings in PHP.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固