Skip to content

A Laravel package to have an internal ID (displayable in the UI), that's unique in the scope of a relationship

License

Notifications You must be signed in to change notification settings

julianstark999/laravel-model-iid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ca98395 · Aug 2, 2021

History

35 Commits
Mar 4, 2021
Aug 2, 2021
Mar 4, 2021
Apr 29, 2021
Apr 29, 2021
Mar 4, 2021
Mar 4, 2021
Aug 2, 2021
Mar 4, 2021
Mar 4, 2021
Mar 4, 2021
Mar 4, 2021
Mar 4, 2021

Repository files navigation

Social Card of Laravel Model Iid

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Add an internal ID to your Eloquent Model

This Laravel package provides the functionality to have an internal ID (displayable in the UI), that's unique in the scope of a relationship

Installation

You can install the package via composer:

composer require julianstark999/laravel-model-iid

Usage

Model

<?php


use JulianStark999\LaravelModelIid\Traits\HasIidColumn;


class Task extends Model
{
    use HasIidColumn;


    public $iidColumn = 'project_id';

    
    ...
}

Migration

$table->unsignedInteger('iid')->nullable();

// optional (should only be defined for new tables or after generating iids for existing entries)
$table->unique(['project_id', 'iid']);

Commands

iid:generate

The iid:generate command generates missing iid for existing models

php artisan iid:generate {className}

# example
php artisan iid:generate "App\Models\Task"

iid:init

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

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.