PHPackages                             vanthao03596/laravel-ulid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vanthao03596/laravel-ulid

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vanthao03596/laravel-ulid
=========================

Laravel package for ULID (Universally Unique Lexicographically Sortable Identifier)

0.1(4y ago)261MITPHPPHP ^7.4|^8.0

Since Aug 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vanthao03596/laravel-ulid)[ Packagist](https://packagist.org/packages/vanthao03596/laravel-ulid)[ Docs](https://github.com/vanthao03596/laravel-ulid)[ GitHub Sponsors](https://github.com/vanthao03596)[ RSS](/packages/vanthao03596-laravel-ulid/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

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

[](#laravel-package-for-ulid-universally-unique-lexicographically-sortable-identifier)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e512bda37cbef692aa015c96073ee66f96ae90ff6b5df07dd422abe4692a310d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616e7468616f30333539362f6c61726176656c2d756c69642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vanthao03596/laravel-ulid)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0f93aed79b1b9efb69f4a3a8101d8cc78712633ed8a4491d04d9eec1d7f4225d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e7468616f30333539362f6c61726176656c2d756c69642f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/vanthao03596/laravel-ulid/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/9ad25cd2d4486a0e3f78c7dabd32f6512ee83b3a2b9f5dddfae2218c1f8a5ce2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e7468616f30333539362f6c61726176656c2d756c69642f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/vanthao03596/laravel-ulid/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0326cfa0af29d2dc86e58eb0476af8aa6cc58173f3cc4315bb68a08621e722c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76616e7468616f30333539362f6c61726176656c2d756c69642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vanthao03596/laravel-ulid)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require vanthao03596/laravel-ulid
```

Usage
-----

[](#usage)

Generate uld from Str support class

```
// Default ulid generator with the current timestamp & lowercase string
Str::ulid(); // 01FDRXQ57VR4K4RASPT9NPAQC0
// Default ulid generator with the current timestamp & uppercase string
Str::ulid(false); // 01fdrxpmg9njp20z3km461fgax
// Default ulid generator with the given datetime & uppercase string
Str::ulid(false, Carbon::now()->subHour()) // 01FDRTD2K8Z664S24X606N14KD
```

Simply declare a ulid column type in your migration files.

```
Schema::create('foos', function (Blueprint $table) {
    $table->ulid('id')->primary(); // adds primary ulid column
    $table->foreignUlid('user_id')->constrained()->cascadeOnDelete(); // adds ulid foreignkey
    $table->ulidMorphs('taggable'); // adds ulid morphs
    $table->nullableUlidMorphs('likeable'); // adds nullable ulid morphs
});
```

Auto generate ulid column in your model

```
