How can I autoload a custom class in Laravel 5.1?

前端 未结 4 1049
無奈伤痛
無奈伤痛 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:56

    Use composer.json :

       "autoload": {
        "classmap": [
            "database",
            "app/Transformers"
        ]
     },
    

    Add your auto load directories like I added app/Transformers.

    Don't Forget to add run composer dump-autoload.

    The only problem with this method is you need to run composer dump-autoload whenever you add new class do that directory.

    Or You can use "Files" in composer.json.

    "autoload": {
        "files": ["src/MyLibrary/functions.php"]
    }
    

提交回复
热议问题