Laravel - PHP - 通过 Composer 安装 HTML 包失败

时间:2021-07-30 03:39:46

标签: php html css laravel

我正在学习 Laravel PHP,我试图在 PHP 网页中显示一些内容,如图像和音频。但是,它不显示任何图像,而只显示纯文本。所以我尝试通过将一些代码行粘贴到 composer.json 文件和 app.php 文件来安装一些 HTML 包,就像他们在 Undefined namespace html (adding a css file to blade) laravel 中所说的那样。运行XAMPP后,我得到一个错误:

Class "Illuminate\Html\HtmlServiceProvider" not found

我的 PHP 版本是 8.0.8(最新),我的 Laravel 版本是 8.52.0 这是我在 composer.json 中的要求:

"require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.40",
        "laravel/tinker": "^2.5",
        "illuminate/html": "~5.0"
    },

这是 app.php 之一:

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        //Collective\Html\HtmlServiceProvider::class,
        //Illuminate\Html\HtmlServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notificadtions\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,

        /*
'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Arr' => Illuminate\Support\Arr::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'Date' => Illuminate\Support\Facades\Date::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Form'=> Illuminate\Html\FormFacade::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Html'=> Illuminate\Html\HtmlFacade::class,
        'Http' => Illuminate\Support\Facades\Http::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'RateLimiter' => Illuminate\Support\Facades\RateLimiter::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        // 'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'Str' => Illuminate\Support\Str::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,

    ],

请帮忙!

2 个答案:

答案 0 :(得分:1)

不要将此视为对您的攻击,但我一遍又一遍地看到这些问题真的很沮丧......

如果你对一个包有任何问题,总是去真相的来源......在这种情况下,它是 Packagist(它是 composer 包的官方“来源”),它会告诉你它来自哪里还有更多...

所以,如果你这样做,它会让你 here 并且你会看到一个美丽的红色传说:

<块引用>

此包已废弃,不再维护。作者建议改用 laravelcollective/html 包。

因此,您单击推荐的包,您将进入一个新的 Packagist 页面,在右侧 (github) 显示 main repo。当您转到该页面时,您可以在自述文件中看到一个主页,因此您go there

在该页面中,您将看到的第一件事是与其相关的文档,它显示的第一个“元素”是 HTML,这是您要使用的(向您显示 laravelcollective/html 的可用文档版本) {1}})...

所以你 click on that one 看看它是如何使用那个类/助手/服务...


另外一件事,由于 repo 或主页没有说明它支持的 Laravel 版本,请始终检查 source code's composer file。你会看到它需要一些 illuminate/xxxx: ^6.0|^7.0|^8.0,这意味着当前 Laravel 支持的版本是 >= 6.x 而不是 <= 5.8。所以支持 Laravel 8。

该检查适用于任何具有 Laravel 版本约束的包。如果你没有看到任何这些,那么它应该可以被任何 Laravel 版本使用......

答案 1 :(得分:0)

对于 .css 和 .js 文件,您可能只想将它们放入 public/css 和 public/js 文件夹,然后将它们包含在您的资源/视图文件夹中的 Bladeview 模板中。他们通过控制器和 view() 助手的帮助返回这个 Blade 视图。如需更多信息,请咨询Laravel document