Laravel Blade – custom helper

Solution:

You can create your own blade help file.
Create you file (say in app/Helpers/bladeHelpers.php) and add code. For example;

<?php
if (! function_exists('my_custom_number_formt')) {
    /**
     * Format number
     *
     * @param $value
     * @param $attribute
     * @param $data
     * @return boolean
     */
    function my_custom_number_formt($value)
    {

        return number_format($value, 0, ' ', ' ');

    }

}

Then add this file to your composer.json in the autoload section (remember to set the namespace as per your project in the psr4 declaration);

{
... rest of file
"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "MyApp\\Custom\\": "src/"
        },
        "files": [
            "app/Helpers/bladeHelpers.php"
        ]
    },
... rest of file
}

N.B You may want to clear your cache at this point.

Then use in your blade files;

<td class="text-right chip-width">{{ my_custom_number_formt($float['chips']['value']) }}</td>