php - 为什么我在 Laravel 5.5.43 中收到“找不到类 'App\Providers\Form'”错误?
问题描述
今天早上我使用以下 Composer 命令安装了 Laravel 5.5.43:
composer create-project laravel/laravel project-name
然后我在项目文件夹中运行以下命令来安装 Laravel Collective:
composer require "laravelcollective/html":"^5.4.0"
providers
然后我在下面添加了以下内容config/app.php
:
Collective\Html\HtmlServiceProvider::class,
aliases
我在下面添加了以下内容config/app.php
:
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
之后,我想创建自定义表单组件,所以我运行了以下 Artisan 命令:
php artisan make:provider FormServiceProvider
在那个新的提供程序文件中,我在方法中添加了以下行boot
:
Form::component('customText', 'components.form.text', ['name', 'value' => null, 'attributes' => []]);
最后,我在providers
in 中添加了以下内容config/app.php
:
App\Providers\FormServiceProvider::class,
当我这样做并从浏览器刷新 Laravel 实例时,我收到以下错误:
Class 'App\Providers\Form' not found
但是,如果我在文件顶部添加以下内容FormServiceProvider.php
,则它可以工作:
use Collective\Html\FormFacade AS Form;
我了解名称空间的概念以及为什么这会使文件中的Form::component
方法中的boot
方法正常工作,但我不明白为什么我需要将该use
行添加到文件中。
文件中数组中的'Form' => Collective\Html\FormFacade::class,
行不是应该为我做的,所以我根本不需要添加行吗?我错过了什么/做错了什么/不理解?aliases
app.php
use
FormServiceProvider.php
谢谢你。
解决方案
I probably should just delete this question, but the simple answer was to add the following at the top of the FormServiceProvider.php
file:
use Form;
Thanks.
推荐阅读
- python - Simple-Salesforce API 版本
- javascript - 用javascript计算日期时间(以天为单位)
- c# - 使用指针在函数中传递公共变量的地址
- sql - 如何在包含百分比的列中获得百分比计算的确切值
- reactjs - 如何从 objectArray 访问对象的字段
- spring - PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:导入从 start.spring.io 生成的项目时
- javascript - 特定 div 的突变观察者
- r - 如何将向量拆分为特定列表?
- nrwl-nx - 如何使用 Nx 运行单个打字稿文件
- c# - Windows 窗体设计器无法从程序集“Microsoft.VisualStudio.DesignTools.Interaction”加载类型