maarheeze/uuid-laravel
最新稳定版本:1.1.0
Composer 安装命令:
composer require maarheeze/uuid-laravel
包简介
laravel integration for a simple uuid value object
README 文档
README
Laravel integration for maarheeze/uuid. Provides an Eloquent cast and a trait for using uuid's as primary keys.
Requirements
- PHP 8.2+
- Laravel 8–12
Installation
composer require maarheeze/uuid-laravel
Usage
Using UUID as primary key
Add the HasUuidAsId trait to an Eloquent model, a uuid is automatically generated on creation.
use Illuminate\Database\Eloquent\Model; use Maarheeze\CalendarDate\Laravel\Model\Concerns\HasUuidAsId; class Article extends Model { use HasUuidAsId; }
$article = Article::create(['title' => 'Hello world']); $article->getKey(); // returns a UuidInterface instance
Casting a UUID column
Use UuidCast directly on any model attribute to cast it to a UuidInterface.
use Illuminate\Database\Eloquent\Model; use Maarheeze\CalendarDate\Laravel\Model\Casts\UuidCast; class Article extends Model { protected $casts = [ 'related_id' => UuidCast::class, ]; }
License
MIT
统计信息
- 总下载量: 57
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17