Manage counters in your Laravel application.
This package allows you to manage counters in your Laravel application. You can create a counter and increment or decrement it as you need. You can also create a counter with a series or a year, so you can have different counters for different series or years.
This package requires Laravel 10.0 or higher.
You can install the package via composer:
composer require sertxudeveloper/laravel-counters
This package provides a configuration file, in order to publish it, you should run the following command:
php artisan vendor:publish --tag=counters-config
In this configuration file you will be able to configure the database connection the package should use for its migrations and models. By default, will use the default database connection defined in your Laravel project.
Next, you should run the migrations:
php artisan migrate
That's it! You are ready to use the package.
Here is an example of how to use the package:
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES');
$invoice->number = $counter->next(); // 1
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES', series: 'N');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->next(); // 2
$counter = Counter::make('INVOICES', series: 'R');
$invoice->number = $counter->next(); // 1
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES', year: '2023');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->next(); // 2
$counter = Counter::make('INVOICES', year: '2024');
$invoice->number = $counter->next(); // 1
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES', year: '2023', series: 'N');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->next(); // 2
$counter = Counter::make('INVOICES', year: '2023', series: 'R');
$invoice->number = $counter->next(); // 1
$counter = Counter::make('INVOICES', year: '2024', series: 'N');
$invoice->number = $counter->next(); // 1
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->next(); // 2
$invoice->number = $counter->decrement(); // 1
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->increment(5); // 6
use SertxuDeveloper\Counters\Counter;
$counter = Counter::make('INVOICES');
$invoice->number = $counter->next(); // 1
$invoice->number = $counter->increment(5); // 6
$invoice->number = $counter->decrement(3); // 3
This package contains tests, you can run them using the following command:
composer test
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Copyright © 2024 Sertxu Developer