Skip to content

Easy creation of unique number for your Eloquent models in Laravel

License

Notifications You must be signed in to change notification settings

mariuszmalek/unique-number-generator

Repository files navigation

Unique-Number-Generator

Easy creation of unique number generator for your Eloquent models in Laravel.

NOTE: These instructions are for the latest version of Laravel.
If you are using an older version, please install a version of the package that correlates to your Laravel version.

Installation

Depending on your version of Laravel, you should install a different version of the package.

  1. Install the package via Composer:

    $ composer require mariuszmalek/unique-number-generator:dev-master

    The package will automatically register its service provider.

  2. Optionally, publish the configuration file if you want to change any defaults:

    php artisan vendor:publish --provider="Malek\UniqueNumberGenerator\ServiceProvider"

Usage

Saving a model is easy:

$post->number = GeneratorNumber::generateID(Post::class, 'number', 'CLI-', $params);

The first parameter is $model in which we search an existing class, the second is a specific column in the database.

The next one is the prefix that will be added to the beginning of the result. The last one is the parameters for specific search classes. Only the first two parameters are required

Using traits:

use Malek\UniqueNumberGenerator\Numerable;

class Product extends Model
{
    use Numerable;

    /**
     * @return string
     */
    public function uniqueColumn(): string
    {
        return 'number';
    }
}

You can add a Trait, so that after creating the model, a new unique number will be automatically created. You also need to add the uniqueColumn function which will contain the name of the column to be used.

Bugs, Suggestions, Contributions and Support

Please use Github for reporting bugs, and making comments or suggestions.

See CONTRIBUTING.md for how to contribute changes.

Copyright and License

unique-number-generator was written by Mariusz Malek and is released under the MIT License.

Copyright (c) 2021 Mariusz Malek

About

Easy creation of unique number for your Eloquent models in Laravel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages