简体   繁体   中英

Laravel cannot load 3rd party library

Basically this is what I've done so far:

I have put my 3rd party library in app\\library\\WebName\\Helper\\Helper.php .

This is the content of the Helper.php

namespace WebName\Helper;

class Helper {

    public static function hello() {

        return 'Hello!';
    }
}

Then I modified the composer.json:

"classmap": [
        "app/commands",
        "app/controllers",
        "app/library",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
        ]

And then I executed a composer dump-autoload .

Now, the problem is that when I try to access the Helper class, for example like in this controller:

use WebName\Helper;

class ValidationController extends BaseController {

    public function sayHello() {

        // Verification
        echo Helper::hello();
    }

I get the following error:

{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'WebName\\Helper' not found","file":"C:\\xampp\\htdocs\\webname\\app\\controllers\\ValidationController.php","line":19}}

If class Helper is in namespace WebName\\Helper , then surely you should be using

use WebName\Helper\Helper; 

not

use WebName\Helper;

in your controller ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM