simlux / laravel-model-uuid by simlux

Make usage of UUID in laravel models easy.
130
0
2
Package Data
Maintainer Username: simlux
Maintainer Contact: simlux78@gmail.com (Simon Kleeschulte)
Package Create Date: 2017-08-26
Package Last Update: 2017-08-26
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-18 15:09:06
Package Statistics
Total Downloads: 130
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Model UUID

Installation

composer require simlux/laravel-model-uuid:dev-master

Usage

Creates column uuid and unique index with the migration helper.

<?php

use Illuminate\Database\Eloquent\Model;
use Simlux\LaravelModelUuid\Uuid\UuidModelTrait;

/**
 * Class MyModel
 *
 * @property int    $id
 * @property string $uuid
 *
 * @method static MyModel uuid(string $uuid)
 */
class MyModel extends Model
{
    use UuidModelTrait;
}

Migration

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Simlux\LaravelModelUuid\Migration\UuidMigrationHelper;

class CreateTableRevisions extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('my_models', function (Blueprint $table) {
            $table->unsignedBigInteger('id', true);
            UuidMigrationHelper::uuid($table);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('my_models');
    }
}