定制 cloudcake/laravel-uuid 二次开发

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

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

cloudcake/laravel-uuid

Composer 安装命令:

composer require cloudcake/laravel-uuid

包简介

UUID's for Laravel's Eloquent models.

README 文档

README

Since Laravel 9.x, UUID support for Eloquent is baked right into Laravel.
See Illuminate/Database/Eloquent/Concerns/HasUuids.

This package is now redundant.

Installation

Install via composer using composer require cloudcake/laravel-uuid

Usage

Primary Key UUID's

If you want to use UUID's as your model's primary key, this is for you.

  • Add the Uuid\Traits\UuidPrimaryKey trait to the eloquent model
  • Add the primary key column name if you're not using the default of id (Optional)
use Uuid\Traits\UuidPrimaryKey;

class User extends Authenticatable
{
    use UuidPrimaryKey;

    protected $primaryKey = 'id';
}

Now you'll be able to call User::find('<uuid-here>');.

Additional Field UUID's

In some situations you may want to retain your regular integer based primary key, but add an additional UUID column to your models, for this case, use the Uuid trait.

  • Add the Uuid\Traits\Uuid trait to the eloquent model
  • Add the name of the UUID column
use Uuid\Traits\Uuid;

class User extends Authenticatable
{
    use Uuid;

    protected static $uuidKeyName = 'uuid';
}

And query it as you would any other attribute, User::where('uuid', '<uuid-here>')->first().

Additional Options

Add any/all of the following to your model(s) to fine-tune the package to your needs.

Attribute Description
$uuidKey The name of the UUID column in the database. Defaults to uuid.
$uuidOrdered Whether or not the UUID should use timestamp ordering. Defaults to true.

Example:

use Uuid\Traits\Uuid;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use Uuid;

    /**
     * The name of the UUID column in the database.
     *
     * @var string
     */
    protected static $uuidKey = 'universally_unique_id';

    /**
     * Whether or not the UUID should use timestamp ordering.
     *
     * @var bool
     */
    protected static $uuidOrdered = true;
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固