oanhnn/laravel-ulid

A Laravel package for ULID (Universally Unique Lexicographically Sortable Identifier)

dev-master 2019-02-21 08:30 UTC

This package is auto-updated.

Last update: 2024-02-21 19:49:08 UTC


README

Latest Version Software License Build Status Coverage Status Total Downloads Requires PHP

A Laravel package for ULID (Universally Unique Lexicographically Sortable Identifier).

TODO

  • Make repository on Github
  • Make repository on Travis
  • Make repository on Coveralls
  • Make repository on Packagist
  • Write logic classes
  • Write test scripts
  • Write README & documents

Requirements

  • php >=7.1.3
  • Laravel 5.5+

Installation

Begin by pulling in the package through Composer.

$ composer require oanhnn/laravel-ulid

Usage

To let a model make use of ULIDs, you must add a ulid field as the primary field in the table.

Schema::create('table_name', function (Blueprint $table) {
    $table->ulid('id');
    $table->primary('id');

    // other fields
});

To get your model to work with the encoded ULID (i.e. to use ulid as a primary key), you must let your model use the Laravel\Ulid\HasUlid trait.

use Illuminate\Database\Eloquent\Model;
use Laravel\Ulid\HasUlid;

class TestModel extends Model
{
    use HasUlid;

    // other logic codes
}

Creating a model

The UUID of a model will automatically be generated upon save.

$model = MyModel::create();
dump($model->getKey());

Changelog

See all change logs in CHANGELOG

Testing

$ git clone git@github.com/oanhnn/laravel-ulid.git /path
$ cd /path
$ composer install
$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email to Oanh Nguyen instead of using the issue tracker.

Credits

License

This project is released under the MIT License.
Copyright © Oanh Nguyen.