Convert Figma logo to code with AI

webpatser logolaravel-uuid

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.

1,802
150
1,802
0

Quick Overview

Laravel-uuid is a Laravel package that provides UUID (Universally Unique Identifier) functionality for Laravel applications. It allows easy generation and usage of UUIDs in Laravel models and database migrations.

Pros

  • Seamless integration with Laravel's Eloquent ORM
  • Supports both UUID v1 and v4 generation
  • Provides a trait for easy implementation in models
  • Compatible with multiple Laravel versions

Cons

  • Limited to Laravel framework, not usable in other PHP projects
  • Requires additional configuration for database columns
  • May have performance implications when used extensively
  • Not actively maintained (last update was in 2019)

Code Examples

  1. Generate a UUID:
use Webpatser\Uuid\Uuid;

$uuid = Uuid::generate();
echo $uuid; // Outputs: 123e4567-e89b-12d3-a456-426614174000
  1. Use UUID in a model:
use Webpatser\Uuid\Uuid;

class User extends Model
{
    use HasUuid;

    protected $primaryKey = 'uuid';
    public $incrementing = false;

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($model) {
            $model->{$model->getKeyName()} = Uuid::generate()->string;
        });
    }
}
  1. Create a migration with UUID:
Schema::create('users', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamps();
});

Getting Started

  1. Install the package via Composer:

    composer require webpatser/laravel-uuid
    
  2. Add the service provider to config/app.php:

    'providers' => [
        // ...
        Webpatser\Uuid\UuidServiceProvider::class,
    ]
    
  3. Add the Facade to config/app.php:

    'aliases' => [
        // ...
        'Uuid' => Webpatser\Uuid\Uuid::class,
    ]
    
  4. Use the HasUuid trait in your models and configure your migrations to use UUID fields as shown in the code examples above.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Laravel UUID Integration

Total Downloads PHP Version Laravel Version License

Laravel package for generating and working with UUIDs. Automatic UUID model keys, validation rules, and Eloquent support.

Installation

composer require webpatser/laravel-uuid

Requirements: PHP 8.2+, Laravel 11.x or 12.x

Quick Start

use Illuminate\Support\Str;
use Webpatser\LaravelUuid\HasUuids;

// High-performance UUID generation
$uuid = Str::fastUuid();                // 15% faster than Str::uuid()
$ordered = Str::fastOrderedUuid();      // Database-optimized

// Eloquent model integration
class User extends Model 
{
    use HasUuids; // Automatic UUID generation
}

Documentation

For complete documentation, examples, and API reference, visit:

https://documentation.downsized.nl/laravel-uuid

License

MIT License.