The package provides a class to generate running number, keep track of them in database table. One running number type can have many prefix to generate running number. Generated running numbers was not stored in database, just keep last number for each prefix. You can reset it to specified value for each prefix. If specified type and prefix does not exists in the database, it will be create and assign number to 1.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
You can install the package via composer:
composer require soap/laravel-running-numbers
You can publish and run the migrations with:
php artisan vendor:publish --tag="running-numbers-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="running-numbers-config"
This is the contents of the published config file:
return [
'table_prefix' => '',
];
Using RunningNumber class to generate running number is deprecated. Now I introduced RunningNumberGenerator class instead.
RunningNumber::generate('STUDENT_CODE', '672', 3);
// 673001
RunningNumber::generate('STUDENT_CODE', '672', 3);
// 673002
// Reset specified type and prefix to some value
RunningNumber::reset('STUDENT_CODE', '672', 0);
RunningNumber::generate('STUDENT_CODE', '672', 3);
// 673001
RunningNumber::delete('STUDENT_CODE', '672');
This is from my implementation.
namespace App\Observers;
use App\Models\Student;
use App\Models\EducationLevel;
use Soap\Laravel\RunningNumbers\RunningNumber;
class StudentObserver
{
/**
* Handle the Student "creating" event.
*
* @return void
*/
public function creating(Student $student)
{
if (empty($student->student_code)) {
$level = EducationLevel::find($student->education_level_id)->level;
$prefix = ($student->registered_at->year + 543) % 100 . $level;
$student->student_code = RunningNumber::generate('STUDENT_CODE', $prefix, 3);
}
}
}
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->generate();
If type was not provided, 'Default' will be used. If prefix was not provided, date("Y") will be used.
Availabe token are {TYPE}, {PREFIX}, {NUMBER}. These information will be keep tracked in database record.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->format("{PREFIX}-{NUMBER}")->generate();
Zero value if no value passed. Call generate(), running number will be increased by one and saved to database.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->reset()->generate();
// return 672-001
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->reset(1)->generate();
// return 672-002
If not set length of 3 will be used.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->length(4)->reset()->generate();
// return 672-0001
Usage:
runningnumber:list [<type> [<prefix>]]
Arguments:
type Type of running number
prefix Prefix before running number
Usage:
runningnumber:generate [options] [--] <type> <prefix>
Arguments:
type Type of running number
prefix Prefix before running number
Usage:
runningnumber:reset [options] [--] <type> <prefix>
Arguments:
type Type of running number
prefix Prefix before running number
Options:
--value[=VALUE] Value to reset running number to [default: "1"]
Usage:
runningnumber:delete <type> <prefix>
Arguments:
type Type of running number
prefix Prefix before running number
composer test
Please see CHANGELOG for more information on what has changed recently.
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.