Storm Spirit
Storm Spirit

Reputation: 1510

Laravel 5 - Helper on Blade not working

I have this error when I used {{ Helper::test(); }} on a blade

enter image description here

and on my config/app.php, I already have enter image description here

and this is inside of my Helper.php

<?php namespace App;

class Helper {
    public static function test() {
        return "wa";
    }
}

and I already done the composer.json then run the composer dump-autoload

...
"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "app/Helper.php"
        ]
    },
...

I don't know what I missed, is there any suggestion to be able to use the helper on a blade on a laravel 5?

Upvotes: 0

Views: 2083

Answers (1)

pinkal vansia
pinkal vansia

Reputation: 10330

You can do this in two different ways,

First

Remove,

 "files": [
            "app/Helper.php"
        ]

from composer.json and remove

"Helper" =>"App\Helper"

from app.php and than use like below,

{{ App\Helper::test() }}

Second

keep composer.json as it is and remove

namespace App;

from Helper.php than run composer dump-autoload and use it as below,

{{ Helper::test() }}

Upvotes: 2

Related Questions