php Composer 自动加载 Laravel 5.5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48123356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:36:48  来源:igfitidea点击:

Composer Autoload Laravel 5.5

phplaravellaravel-5composer-phpautoload

提问by Elias Tutungi

I started a laravel project in version 5.5, I have been working with version 5.1.

我在 5.5 版本中开始了一个 Laravel 项目,我一直在使用 5.1 版本。

In this version I use the folder 'nob' and I use it to develop some classes to turn them into components.

在这个版本中,我使用文件夹“nob”,我用它来开发一些类以将它们转换为组件。

I used the following composer.json in the version 5.1:

我在 5.1 版本中使用了以下 composer.json:

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\": "app/",
        "Nob\": "nob/"
    }
},

And this is the version 5.5:

这是 5.5 版:

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\": "app/",
        "Nob\": "nob/"
    }
},

I get this error: enter image description here

我收到此错误: 在此处输入图片说明

This is the class, her namespace is correct

这是类,她的命名空间是正确的

<?php namespace Nob\Payeezy\Types;

use Nob\Payeezy\Payeezy;

class Authorization extends Payeezy
{

And this is the tree:

这是树:

enter image description here

在此处输入图片说明

I use PhpStorm and he recognizes the namespaceenter image description here

我使用 PhpStorm,他识别出命名空间在此处输入图片说明

I do not know what may be happening, I used composer dump-autoload and nothing.

我不知道可能会发生什么,我使用了 composer dump-autoload 而什么也没有。

回答by Joan Nguyen

Your code is correct when I tried on my PhpStorm. But you can run the following three commands:

当我在我的 PhpStorm 上尝试时,您的代码是正确的。但是您可以运行以下三个命令:

$ php artisan clear-compiled 
$ composer dump-autoload
$ php artisan optimize

And this will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.

这将清除当前编译的文件,更新它需要的类,然后将它们写回,这样你就不必再做一次了。

回答by Gautam Patadiya

You can use this commands may can help you:

您可以使用此命令可能可以帮助您:

composer dump-autoload -o

Good Luck

祝你好运