Create UIDs like the ones Stripe generates. These can be used on your models or on their own.
alecgarcia/laravel-uid is a Laravel package for create uids like the ones stripe generates. these can be used on your models or on their own..
It currently has 0 GitHub stars and 9 downloads on Packagist (latest version v1.0.0).
Install it with composer require alecgarcia/laravel-uid.
Discover more Laravel packages by alecgarcia
or browse all Laravel packages to compare alternatives.
Last updated
This package creates UIDs like the ones Stripe uses for your models or on their own.
$ composer require alecgarcia/laravel-uid
php artisan make:migration --table users add-uid-to-users
uid field.
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('uid', 32)->after('id')->unique();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('uid');
});
}
uid field
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('uid', 32)->unique();
$table->timestamps();
});
}
<?php
namespace App\Models;
use Alecgarcia\LaravelUid\Traits\Uid;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use UID;
}
<?php
use Alecgarcia\LaravelUid\Uid;
$generatedUid = Uid::make();
// Generated Uid -> "1mVQuIwVrRS9ijwx" // Defaults to no prefix and 16 Characters long
$generatedUid = Uid::make('uid', 12);
// Generated Uid -> "uid_nuv8V6GH" // Can set the prefix that is used and the length
You can add the following properties to your model to configure the Uid trait.
<?php
namespace App\Models;
use Alecgarcia\LaravelUid\Traits\Uid;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use UID;
public static string $uidPrefix = 'usr'; // Defaults to models class name
public static int $uidLength = 10; // Defaults to 16 total characters
public static bool $uidCheck = false; // Default is true
public static string $uidColumn = 'uidCustomColumn'; // Default is uid
}
$ php artisan vendor:publish --tag laravel-uid.config
app/config/laravel-uid.php file.<?php
return [
/*
|--------------------------------------------------------------------------
| Customize how the uid is created and used
|--------------------------------------------------------------------------
*/
'characters' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'prefix_separator' => '_',
'uid_column' => 'uid',
'length' => 16,
'check' => true,
];
Please see the changelog for more information on what has changed recently.
$ php vendor/bin/phpunit
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.