This Laravel package provides the functionality to have an internal ID (displayable in the UI), that's unique in the scope of a relationship
You can install the package via composer:
composer require julianstark999/laravel-model-iid
<?php
use JulianStark999\LaravelModelIid\Traits\HasIidColumn;
class Task extends Model
{
use HasIidColumn;
public $iidColumn = 'project_id';
...
}
$table->unsignedInteger('iid')->nullable();
// optional (should only be defined for new tables or after generating iids for existing entries)
$table->unique(['project_id', 'iid']);
The iid:generate
command generates missing iid for existing models
php artisan iid:generate {className}
# example
php artisan iid:generate "App\Models\Task"
The iid:init
command initializes the iid for existing models by using the id column
php artisan iid:generate {className}
# example
php artisan iid:init "App\Models\Task"
Recommended using if you already use the id
column for display
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.