How can I autoload a custom class in Laravel 5.1?

前端 未结 4 1050
無奈伤痛
無奈伤痛 2021-02-08 21:32

I\'ve created a library folder within the app folder to add my own classes.

This is the content of the file app/library/helper.p

4条回答
  •  一向
    一向 (楼主)
    2021-02-08 21:40

    I know this question was answered a while ago, but the reason it isn't working is that you need to give the namespace that corresponds with the file structure. Therefore, since the Library class is inside the App folder you need:

    namespace App\Library;
    
    class MyHelper{
        public function v($arr){
            var_dump($arr);
        }
    }
    

    Additionally, if you are going to call the class MyHelper, you need to call the file MyHelper.php

提交回复
热议问题