Search code examples
laravellaravel-5laravel-5.3

How to call static function from Helper in Laravel blade file?


I have custom class in path:

app/Http/Helpers/Helper/Helper.php 

with namespace is: namespace App\Helpers;

It has a static method:

public static function getMonthName($monthNumber)
{
    return date("F", mktime(0, 0, 0, $monthNumber, 1));
}

I tried to call this method from template Laravel:

{{ \App\Http\Helpers\Helper::getMonthName($i) }}

But it does not work:

Class 'App\Http\Helpers\Helper' not found

Solution

  • update the namespace to be :

    namespace App\Http\Helpers\Helper;
    

    namespace must be the same as the class path, because laravel uses spl_autoload to load classes dynamically