PHPackages                             labrodev/laravel-numberable - 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. [Database &amp; ORM](/categories/database)
4. /
5. labrodev/laravel-numberable

ActiveLibrary[Database &amp; ORM](/categories/database)

labrodev/laravel-numberable
===========================

Laravel package providing a reusable trait that automatically assigns a document number to Eloquent models upon creation.

v1.0.2(9mo ago)023MITPHPPHP &gt;=8.2

Since Nov 10Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/labrodev/laravel-numberable)[ Packagist](https://packagist.org/packages/labrodev/laravel-numberable)[ Docs](https://github.com/labrodev/laravel-numberable)[ RSS](/packages/labrodev-laravel-numberable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (14)Versions (4)Used By (0)

Numberable for Laravel
======================

[](#numberable-for-laravel)

Numberable is a Laravel package that provides a reusable trait for automatically assigning a number to Eloquent models upon their creation.

By default it generates a unique document number based on the model's ID and the current year. This method can be customized in individual models that use the trait, allowing for flexible document numbering logic.

- Base Year: Uses the current year as the prefix for the document number.
- Prediction Number: Sets a default "prediction number" (e.g., 10000), determining the minimum length of the number portion.
- Padding: Pads the model ID with leading zeros to match the length of the prediction number, ensuring consistent document number lengths.

For example, if the current year is 2024 and the model ID is 45 and prediction number is 10000, the generated document number would be: 202400045.

But you are free to provide your own logic of generation for specific models.

You just need to overwrite method `protected function generateNumberByTraitModelHasNumber(int $modelId): string` in your model.

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

[](#installation)

To install the package, run the following command in your Laravel project:

```
composer require labrodev/numberable
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher

Configuration
-------------

[](#configuration)

After installing the package, no additional configuration is needed to start using the UUID trait in your models.

Usage
-----

[](#usage)

To use the `ModelHasNumber` trait, simply include it in your Eloquent model:

```
