简体   繁体   English

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

[英]Laravel - PHP - Installing HTML packages via composer failed

I'm learning Laravel PHP and I was trying to display some contents like images and audio in a PHP webpage.我正在学习 Laravel PHP,我试图在 PHP 网页中显示一些内容,如图像和音频。 However, it didn't display any images but only plain texts.但是,它不显示任何图像,而只显示纯文本。 So I tried to install some HTML packages by pasting some lines of codes to composer.json file and app.php file like what they said in Undefined namespace html (adding a css file to blade) laravel .所以我尝试通过将一些代码行粘贴到 composer.json 文件和 app.php 文件来安装一些 HTML 包,就像他们在Undefined namespace html (adding a css file to Blade) laravel 中所说的那样 After running XAMPP, I obtained an error:运行 XAMPP 后,我得到一个错误:

Class "Illuminate\Html\HtmlServiceProvider" not found

My PHP version is 8.0.8 (latest) and my Laravel version is 8.52.0 Here is my require in composer.json:我的 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"
    },

And here is the app.php one:这是 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,

    ],

Please help!请帮忙!

Do not take this as an attack to you, but I get really frustrated seeing this questions over and over again...不要认为这是对你的攻击,但我一遍又一遍地看到这些问题真的很沮丧......

If you have any problems with a package, ALWAYS go to the source of truth... In this case it would be Packagist (it is the official "source" for composer packages) and it will tell you where it comes from and more...如果您对某个包有任何问题,请始终查找事实来源...在这种情况下,它将是 Packagist(它是 Composer 包的官方“源”),它会告诉您它来自哪里等等。 ..

So, if you do that, it will get you here and you will see a beautiful red legend saying:所以,如果你这样做,它会把你带到这里,你会看到一个美丽的红色传说说:

This package is abandoned and no longer maintained.这个包被放弃了,不再维护。 The author suggests using the laravelcollective/html package instead.作者建议改用laravelcollective/html包。

So, you click that recommended package and you got to a new Packagist page, showing the main repo on the right side (github).所以,你点击推荐的包,你会进入一个新的 Packagist 页面,在右侧 (github) 显示主存储库。 When you go to that page, you can see a main page in the readme, so you go there .当您转到该页面时,您可以在自述文件中看到一个主页,因此您可以前往该页面

In that page, the first thing you will see is the documentation related to it, and the first "element" it shows is HTML , the one you want to use (showing you the available doc's versions for laravelcollective/html )...在该页面中,您将看到的第一件事是与它相关的文档,它显示的第一个“元素”是HTML ,您要使用的那个(向您显示laravelcollective/html的可用文档版本)...

So you click on that one and see how it is to just use that class/helper/service...所以你点击那个,看看它是如何使用那个类/助手/服务......


One more thing, as the repo or the main page does not say the Laravel versions it support, always check the source code's composer file .还有一件事,由于 repo 或主页没有说明它支持的 Laravel 版本,请始终检查源代码的 composer file You will see it requires some illuminate/xxxx: ^6.0|^7.0|^8.0 , that means that the current Laravel supported version is >= 6.x but not <= 5.8 .你会看到它需要一些 light illuminate/xxxx: ^6.0|^7.0|^8.0 ,这意味着当前 Laravel 支持的版本是>= 6.x但不是<= 5.8 So Laravel 8 is supported.所以支持 Laravel 8。

That check works for any package that has a constraint with a Laravel version.该检查适用于任何具有 Laravel 版本约束的包。 If you don't see any of that, then it should be usable by any Laravel version...如果你没有看到任何这些,那么它应该可以被任何 Laravel 版本使用......

For .css and .js files, you may want to just put them into public/css and public/js folder and then include them in Bladeview templates in your resources/views folder.对于 .css 和 .js 文件,您可能只想将它们放入 public/css 和 public/js 文件夹,然后将它们包含在您的资源/视图文件夹中的 Bladeview 模板中。 Them you return this Blade view via the help of controller and view() helper.他们通过控制器和view()助手的帮助返回这个 Blade 视图。 For more information please consult Laravel document更多信息请参考Laravel 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM