mardi 29 décembre 2015

Can't access Laravel helper class from a view

I have my Helper file located at app/Helpers/Helper.php

class Helper {

    // Add body class
    public static function bodyClass() {
        $body_classes = array();
        $class = "";

        foreach ( \Request::segments() as $segment ) {
            if ( is_numeric( $segment ) || empty( $segment ) ) {
            continue;
            }

            $class .= ! empty( $class ) ? "-" . $segment : $segment;
            array_push( $body_classes, $class );
        }
        return ! empty( $body_classes ) ? implode( ' ', $body_classes ) : NULL;
    }
}

Then in my composer.json, I autoloaded this Helper file like this:

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

Then in one of my master views, I have this:

<body class="{{ Helper::bodyClass() }}">

But I get an error saying:

Class 'Helper' not found

I also did dump autoload so that shouldn't be the issue. Anyone have any clues?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire