sertxudeveloper / laravel-counters
Manage counters with year and series.
Fund package maintenance!
sertxudev
buymeacoffee.com/sertxudeveloper
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
This package is auto-updated.
Last update: 2024-11-18 17:08:19 UTC
README
Laravel Counters
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.
Requirements
This package requires Laravel 10.0 or higher.
Installation
You can install the package via composer:
composer require sertxudeveloper/laravel-counters
Usage
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 a basic counter
use SertxuDeveloper\Counters\Counter; $counter = Counter::make('INVOICES'); $invoice->number = $counter->next(); // 1
Use a counter with a series
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 a counter with a year
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 a counter with a year and a series
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
Decrement a counter
use SertxuDeveloper\Counters\Counter; $counter = Counter::make('INVOICES'); $invoice->number = $counter->next(); // 1 $invoice->number = $counter->next(); // 2 $invoice->number = $counter->decrement(); // 1
Custom increment
use SertxuDeveloper\Counters\Counter; $counter = Counter::make('INVOICES'); $invoice->number = $counter->next(); // 1 $invoice->number = $counter->increment(5); // 6
Custom decrement
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
Testing
This package contains tests, you can run them using the following command:
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
Copyright © 2024 Sertxu Developer