{"id":13396120,"url":"https://github.com/webpatser/laravel-uuid","last_synced_at":"2025-05-14T02:06:21.438Z","repository":{"id":10609106,"uuid":"12826562","full_name":"webpatser/laravel-uuid","owner":"webpatser","description":"Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.","archived":false,"fork":false,"pushed_at":"2023-12-12T12:48:38.000Z","size":94,"stargazers_count":1806,"open_issues_count":10,"forks_count":152,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-10T16:48:40.243Z","etag":null,"topics":["laravel-uuid","laravel-validation","php","uuid"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webpatser.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-09-14T08:35:28.000Z","updated_at":"2025-04-05T21:09:11.000Z","dependencies_parsed_at":"2024-01-15T18:44:53.917Z","dependency_job_id":"cc8c4553-974d-4a07-9c86-7c8cad4c5ae0","html_url":"https://github.com/webpatser/laravel-uuid","commit_stats":{"total_commits":73,"total_committers":13,"mean_commits":5.615384615384615,"dds":"0.23287671232876717","last_synced_commit":"df92ebbc5ea71ee9e0d6e2861178be42ef7eb330"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpatser%2Flaravel-uuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpatser%2Flaravel-uuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpatser%2Flaravel-uuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpatser%2Flaravel-uuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webpatser","download_url":"https://codeload.github.com/webpatser/laravel-uuid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052697,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel-uuid","laravel-validation","php","uuid"],"created_at":"2024-07-30T18:00:40.696Z","updated_at":"2025-05-14T02:06:16.427Z","avatar_url":"https://github.com/webpatser.png","language":"PHP","funding_links":[],"categories":["Popular Packages","PHP","Packages","字符串( Strings )","插件推荐"],"sub_categories":["Development Tools"],"readme":"# Laravel Uuid\n\n[![Total Downloads](https://poser.pugx.org/webpatser/laravel-uuid/downloads.svg)](https://packagist.org/packages/webpatser/laravel-uuid)\n[![Build Status](https://secure.travis-ci.org/webpatser/laravel-uuid.png?branch=master)](http://travis-ci.org/webpatser/laravel-uuid)\n[![codecov.io](http://codecov.io/github/webpatser/laravel-uuid/coverage.svg?branch=master)](http://codecov.io/github/webpatser/laravel-uuid?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/webpatser/laravel-uuid/v/stable.svg)](https://packagist.org/packages/webpatser/laravel-uuid)\n[![Licence](https://poser.pugx.org/webpatser/laravel-uuid/license.svg)](https://packagist.org/packages/webpatser/laravel-uuid)\n\nLaravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for version 1, 3, 4 and 5 UUIDs are built-in.\n\n## What's new in 4.*\nLaravel-uuid is now ready for Laravel 8. It has the same requirements so that means PHP 7.3 or PHP 8. Laravel package auto-discovery is enabled, and you can now use the UUID validation. Validation examples are below and in the tests.\n\nFor older Laravel or PHP versions use older versions; see below...\n\n## What's new in 3.*\nLaravel-uuid is now refactored for Laravel 5.5. It has the same requirements so that means PHP 7. Laravel package auto-discovery is enabled, and you can now use the UUID validation. Validation examples are below and in the tests. \n\nLaravel 5.0, 5.1, 5.2, 5.3 and 5.4? use  [version 2](https://github.com/webpatser/laravel-uuid/tree/2.1.1)\n\nLaravel 4.*? use [version 1](https://github.com/webpatser/laravel-uuid/tree/1.5)\n\n## Installation\n\nIn Laravel 5.5 laravel-uuid will install via the new package discovery feature so you only need to add the package to your composer.json file\n\n```shell\ncomposer require \"webpatser/laravel-uuid:^3.0\"\n```\n\nafter installation you should see\n\n```shell\nDiscovered Package: webpatser/laravel-uuid\n```\n\nand you are ready to go\n\n## Basic Usage\n\nTo quickly generate a UUID just do\n\n```php\nUuid::generate()\n```\n\t\nThis will generate a version 1 Uuid `object` with a random generated MAC address.\n\nTo echo out the generated UUID, cast it to a string\n\n```php\n(string) Uuid::generate()\n```\n\nor\n\n```php\nUuid::generate()-\u003estring\n```\n\n## Advanced Usage\n\n### UUID creation\n\nGenerate a version 1, time-based, UUID. You can set the optional node to the MAC address. If not supplied it will generate a random MAC address.\n\n```php\nUuid::generate(1,'00:11:22:33:44:55');\n```\n\t\nGenerate a version 3, name-based using MD5 hashing, UUID\n\n```php\nUuid::generate(3,'test', Uuid::NS_DNS);\n```\t\n\nGenerate a version 4, truly random, UUID\n\n```php\nUuid::generate(4);\n```\n\nGenerate a version 5, name-based using SHA-1 hashing, UUID\n\n```php\nUuid::generate(5,'test', Uuid::NS_DNS);\n```\n\t\n### Some magic features\n\nTo import a UUID\n\n```php\n$uuid = Uuid::import('d3d29d70-1d25-11e3-8591-034165a3a613');\n```\t\n\nExtract the time for a time-based UUID (version 1)\n\n```php\n$uuid = Uuid::generate(1);\ndd($uuid-\u003etime);\n```\n\nExtract the version of an UUID\n\n```php\n$uuid = Uuid::generate(4);\ndd($uuid-\u003eversion);\n```\n\n## Eloquent UUID generation\n\nIf you want an UUID magically be generated in your Laravel models, just add this boot method to your Model.\n\n```php\n/**\n *  Setup model event hooks\n */\npublic static function boot()\n{\n    parent::boot();\n    self::creating(function ($model) {\n        $model-\u003euuid = (string) Uuid::generate(4);\n    });\n}\n```\nThis will generate a version 4 UUID when creating a new record.\n\n## Model binding to UUID instead of primary key\n\nIf  you want to use the UUID in URLs instead of the primary key, you can add this to your model (where 'uuid' is the column name to store the UUID)\n\n```php\n/**\n * Get the route key for the model.\n *\n * @return string\n */\npublic function getRouteKeyName()\n{\n    return 'uuid';\n}\n```\n\nWhen you inject the model on your resource controller methods you get the correct record\n\n```php\npublic function edit(Model $model)\n{\n   return view('someview.edit')-\u003ewith([\n        'model' =\u003e $model,\n    ]);\n}\n```\n\n## Validation\n\nJust use like any other Laravel validator.\n\n``'uuid-field' =\u003e 'uuid'``\n\nOr create a validator from scratch. In the example an Uuid object in validated. You can also validate strings `$uuid-\u003estring`, the URN `$uuid-\u003eurn` or the binary value `$uuid-\u003ebytes`\n\n```php\n$uuid = Uuid::generate();\n$validator = Validator::make(['uuid' =\u003e $uuid], ['uuid' =\u003e 'uuid']);\ndd($validator-\u003epasses());\n```\n\n## Notes\n\nFull details on the UUID specification can be found on [http://tools.ietf.org/html/rfc4122](http://tools.ietf.org/html/rfc4122).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpatser%2Flaravel-uuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebpatser%2Flaravel-uuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpatser%2Flaravel-uuid/lists"}