Coder Social home page Coder Social logo

referencenumber's Introduction

#Laravel Reference Number Trait

Generate a reference number for Invoices, Payment Transactions, Form Submissions, etc

Installation

You can install the package via composer:

composer require stryksta/referencenumber

Options

Option Type Default Description
field string reference_number This is used to identify the field the generated reference number will be saved to.
start integer 0 This is where incrementing will start. When generating a reference number this will always increment by 1. So if you start at 0, your first reference will be 1.
prefix string '' This is a string you want added in front of every reference number
suffix string '' This is a string you want added to the end of every reference number
padding integer '' This will pad the reference number to a specified length. For example, setting padding to 3 will generate 001, 002, 003 and so on.

Usage

  1. Your model should use the Stryksta\ReferenceNumber\GenerateReferenceNumber trait
  2. You should have a field to save the generated reference number to.

Here's an example of how to implement the trait:

<?php

namespace App;

use Stryksta\ReferenceNumber\GenerateReferenceNumber;
use Illuminate\Database\Eloquent\Model;

class SubmissionModel extends Model
{
    use GenerateReferenceNumber;
   
    /**
     * Get the options for generating a reference number
     */
    public function referenceNumberOptions()
    {
        return [
            'field' => 'reference_number',
            'start' => 0,
            'prefix' => 'S',
            'suffix' => '',
            'padding' => 3,
        ];
    }
}
    public function create() {
        $model = new SubmissionModel();
        $model->name = 'John Smith';
        $model->comment = 'Hello';
        $model->save();

        echo $model->reference_number; // ouputs "S001"
}

Changelog

1.0.0 - 2020-01-03

  • Initial release

Testing

composer test

Contributing

Suggestions, Improvements, and any other comments are welcome!

License

The MIT License (MIT). Please see License File for more information.

referencenumber's People

Contributors

strykstaguy avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.