【问题标题】:Laravel - PHP - Installing HTML packages via composer failedLaravel - PHP - 通过作曲家安装 HTML 包失败
【发布时间】:2021-10-05 15:47:57
【问题描述】:

我正在学习 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,

    ],

请帮忙!

【问题讨论】:

  • 在这里查看您的问题stackoverflow.com/questions/28541051/…
  • 我的 Laravel 版本似乎与 HTML 类不兼容。有一些页面说 HTML 在它的特定版本之后从 Laravel 中被弃用。有没有其他方法可以在 PHP 页面中完整显示 HTML 代码?
  • 奇怪的是,composer 一开始就允许你安装它。通常,您会收到版本冲突错误,表明无法全部满足该组包

标签: php html css laravel


【解决方案1】:

不要把这当作对你的攻击,但是我一遍又一遍地看到这个问题真的很沮丧......

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

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

这个包被废弃并且不再维护。作者建议改用laravelcollective/html 包。

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

在该页面中,您首先会看到与它相关的文档,它显示的第一个“元素”是 HTML,即您要使用的那个(向您展示laravelcollective/html 的可用文档版本) )...

所以你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 版本使用......

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 你好。我也试过这个命令:composer require laravelcollective/html 它有错误:-Illumination/html[dev-master,v5.0.0] 需要Illuminate/http ~5.0 -> 找到Illuminate/http[v5.0.0,..., 5.8.x-dev] 但这些没有加载,可能是因为它与另一个需求冲突。你有什么解决办法吗?
    • 你必须删除 illuminate/http 并要求 laravelcollective/html...
    • @matiaslauriti 我成功安装了 laravelcollective/html ,它仍然提示错误: Class HTML not found at the line which is "{{ HTML::image('resources/views/Assets/kifflom. jpg', 'alt text', array('class' => 'css-class')) }}"
    • @HackerRhino 那是因为,如果你看到我的回答并转到documentation,你会看到HTML::image(新的写法是@ 987654329@) 不存在...您必须手动将图像创建为 HTML <img>请阅读我的答案和文档。这是旧的HTML::image source code...
    • @matiaslauriti 我按照你说的做了,只需创建一个普通的 HTML 标签 就可以了。但它并没有真正显示图像。这是结果。 drive.google.com/file/d/1ddXfB8F9XkUhc2pJ9dENiwVJCiN0rlKx/…
    猜你喜欢
    • 2017-02-14
    • 2017-09-15
    • 1970-01-01
    • 2013-12-25
    • 2013-07-10
    • 2018-06-22
    • 2021-11-03
    • 2021-10-21
    相关资源
    最近更新 更多