php 找不到 Laravel 5 类“App\Http\Controllers\File”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29704848/
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 00:31:54  来源:igfitidea点击:

Laravel 5 Class 'App\Http\Controllers\File' not found

phplaravelnamespaceslaravel-5illuminate-container

提问by jerik

i get the following error:

我收到以下错误:

Class 'App\Http\Controllers\File' not found

when using in laravel 5 Controller:

在 laravel 5 控制器中使用时:

$files = File::files( $this->csvDir );

I have to add the Filesystemto composer.jsonand config/app.php. Somehow I use a misconfiguration.

我必须将文件系统添加到composer.jsonconfig/app.php。不知何故,我使用了错误配置。

That's what I changed:

这就是我改变的:

composer.json

作曲家.json

    "require": {
        "laravel/framework": "5.0.*", 
        "illuminate/html": "5.*",
        "illuminate/filesystem": "5.*"  /* my try to repo */
    },

config/app.php

配置/app.php

    'providers' => [

    // [...] 
    // jerik 2015-04-17: get html Forms
    // http://laravel.io/forum/09-20-2014-html-form-class-not-found-in-laravel-5
    'Illuminate\Html\HtmlServiceProvider', 
    'Illuminate\Filesystem\FilesystemServiceProvider', // try to add file

When I run composer update, it runs well, but there is no ouput that the Filesystem is downloaded. So my configuration is wrong, but I do not know the correct way.

当我运行时composer update,它运行良好,但没有下载文件系统的输出。所以我的配置是错误的,但我不知道正确的方法。

Any suggestions or tips?

有什么建议或提示吗?

回答by Marcin Nabia?ek

First you shoud consider using built-in Storage facade. You don't need to include manually Filesystemunless you use S3 or Rackspace because it's already included by default - look at Filesystem in Laravel 5 documentation.

首先,您应该考虑使用内置的 Storage 门面。Filesystem除非您使用 S3 或 Rackspace,否则您不需要手动包含,因为默认情况下已经包含了 - 查看Laravel 5 文档中的文件系统

It also seems, that you should import Fileso try

看来,你应该导入File所以试试

use File;

or \Fileto solve the issue because now you are using File from current namespace and probably Fileis not defined in App\Http\Controllersnamespace

或者\File解决这个问题,因为现在您正在使用当前命名空间中的文件,并且可能File没有在App\Http\Controllers命名空间中定义