The number in words in Laravel 5

    Sometimes it is necessary to display the number in words when forming any form and the DigitText module , designed specifically for the Laravel framework, comes to our aid .

    It allows you to process any number in any language

    image


    Installation


    Installing the module is very simple:

    1. Execute the following commands:

    composer require andrey-helldar/digittext
    composer update
    

    2. After updating the composer, add the service provider to the file `config / app.php`:

    Helldar\DigitText\DigitServiceProvider::class,
    

    3. Next, in the same file, in the `aliases` section, add the facade:

    'DigitText' => Helldar\DigitText\DigitText::class,
    

    Done!

    Using


    To translate a number into text, use the construct:
    DigitText::text($number = 0, $lang = 'ru', $currency = false);
    


    Example:
    DigitText::text();
    DigitText::text(64.42);
    DigitText::text(2866);
    DigitText::text(0, 'ru', true);
    DigitText::text(64.42, 'ru', true);
    DigitText::text(2866, 'ru', true);
    /*
     * Результат:
     *     ноль
     *     шестьдесят четыре
     *     две тысячи восемьсот шестьдесят шесть
     *
     *     ноль руб
     *     шестьдесят четыре руб 42 коп
     *     две тысячи восемьсот шестьдесят шесть руб
     */
    


    Language forms


    At the time of writing, the module supports working with such language forms as: “Russian”, “English” and “German”.

    Anyone can help the development of the DigitText module .

    The module is licensed by MIT.

    From the author


    This is my first module under Laravel. I know that the code is far from ideal and I ask you not to kick much :)

    To minus


    If you do not share the author’s view, please kindly describe your point of view in the comments.

    Also popular now: