php - Laravel - PHP - 通过作曲家安装 HTML 包失败
问题描述
我正在学习 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,
],
请帮忙!
解决方案
不要把这当作对你的攻击,但我一遍又一遍地看到这个问题真的很沮丧......
如果你对一个包有任何问题,总是去找真相的来源......在这种情况下,它会是 Packagist(它是作曲家包的官方“来源”),它会告诉你它来自哪里等等。 ..
所以,如果你这样做,它会带你到这里,你会看到一个美丽的红色传说:
此软件包已废弃且不再维护。作者建议改用laravelcollective/html包。
所以,你点击推荐的包,你会进入一个新的 Packagist 页面,在右侧(github)显示主 repo 。当你去那个页面时,你可以在自述文件中看到一个主页,所以你去那里。
在该页面中,您将看到的第一件事是与之相关的文档,它显示的第一个“元素”是HTML
您要使用的那个(向您显示可用的文档版本laravelcollective/html
)...
所以你点击那个,看看如何使用那个类/助手/服务......
还有一件事,因为 repo 或主页没有说明它支持的 Laravel 版本,所以请始终检查源代码的 composer 文件。你会看到它需要一些illuminate/xxxx: ^6.0|^7.0|^8.0
,这意味着当前 Laravel 支持的版本是>= 6.x
但不是<= 5.8
。所以支持 Laravel 8。
该检查适用于任何具有 Laravel 版本约束的包。如果你没有看到任何这些,那么它应该可以被任何 Laravel 版本使用......
推荐阅读
- bash - Linux sed 命令在每个正则表达式匹配时生成一个新文件
- python - 使用 TPU pod 训练 keras 模型?
- c# - 为什么我在尝试调试时偶尔会遇到断点未命中的问题?
- javascript - 文件未另存为 .png
- android - 位图返回为空
- vba - Powerpoint VBA 选择图像文件夹,将这些图像放在幻灯片上
- sql - 如何聚合循环发生的连续事件序列?
- ansible - 使用 Ansible 确保文件存在,忽略任何额外的行
- markdown - 如何使 Nextjournal 生成的内部 Markdown 链接与 Jekyll 一起使用?
- python - 列表理解中的意外行为