php ReflectionException: Class ClassName 不存在 - Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32475892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ReflectionException: Class ClassName does not exist - Laravel
提问by Nana Partykar
As soon, I am typing php artisan db:seed
command.
很快,我正在输入php artisan db:seed
命令。
I'm getting ErrorLike:
我收到错误,例如:
[ReflectionException]
Class UserTableSeeder does not exist
[ReflectionException]
类 UserTableSeeder 不存在
root@dd-desktop:/opt/lampp/htdocs/dd/laravel# php artisan db:seed
root@dd-desktop:/opt/lampp/htdocs/dd/laravel# php artisan db:seed
Here, Is my UserTableSeeder.php
& DatabaseSeeder.php
Page
在这里,是我的UserTableSeeder.php
&DatabaseSeeder.php
页面
UserTableSeeder.php
UserTableSeeder.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class UserTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(array(
'name' => 'Chris Sevilleja',
'username' => 'sevilayha',
'email' => '[email protected]',
'password' => Hash::make('awesome'),
));
}
}
DatabaseSeeder.php
数据库浏览器.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
$this->call('UserTableSeeder');
}
}
I'm Referring This LinkTo Design & Develop Login Page. Please Help me to resolve this issue. Thanks.
我引用此链接设计和开发登录页面。请帮我解决这个问题。谢谢。
回答by Ahmad Baktash Hayeri
Perform a composer update
, then composer dump-autoload
.
执行 a composer update
,然后composer dump-autoload
。
If the above doesn't solve the problem, change the classmap
in your composer.json
file such that it contains the project-relative path to your php files:
如果以上操作不解决问题,改变classmap
你的composer.json
文件,使之包含项目相关的路径到你的PHP文件:
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"database/seeds/UserTableSeeder.php" //include the file with its path here
]
}, /** ... */
and soon after, perform a composer dump-autoload
, and it should work now like a breeze!
不久之后,执行 a composer dump-autoload
,它现在应该像微风一样工作了!
Edit by @JMSamudio
由@JMSamudio 编辑
If composer dump-autoload
is not found, just enable this option composer config -g -- disable-tls true
.
如果composer dump-autoload
未找到,只需启用此选项composer config -g -- disable-tls true
。
回答by Kamaro Lambert
From my experience, this will show up most of the time when the class you are trying to call has some bugs and cannot be compiled. Check if the class that is not being reflected can be executed at its own.
根据我的经验,当您尝试调用的类有一些错误并且无法编译时,大多数情况下都会出现这种情况。检查未被反射的类是否可以自行执行。
回答by fsavina
A composer dump-autoload
should fix it.
Acomposer dump-autoload
应该修复它。
回答by Luciano Braga
I have the same problem with a class
. I tried composer dump-autoload
and php artisan config:clear
but it did not solve my problem.
我有同样的问题class
。我试过了composer dump-autoload
,php artisan config:clear
但没有解决我的问题。
Then I decided to read my code to find the problem and I found the problem. The problem in my case was a missing comma in my class. See my Model code:
然后我决定阅读我的代码以找到问题,我找到了问题。我的问题是我班上缺少逗号。查看我的型号代码:
{
protected
$fillable = ['agente_id', 'matter_id', 'amendment_id', 'tipo_id'];
public
$rules = [
'agente_id' => 'required', // <= See the comma
'tipo_id' => 'required'
];
public
$niceNames = [
'agente_id' => 'Membro', // <= This comma is missing on my code
'tipo_id' => 'Membro'
];
}
回答by Jaroslav Klim?ík
For some reason I had to run composer dumpautoload -o
. Notice flag -o
which mean with optimization. I don't have any idea why it works only with it but give it a try. Perhaps it helps someone.
出于某种原因,我不得不运行composer dumpautoload -o
. 注意标志-o
,这意味着优化。我不知道为什么它只适用于它,但试一试。也许它可以帮助某人。
回答by Adam Ranganathan
I had this problem and I could solve it by doing php artisan config:cache
. The problem was that I had already run that command previously and later included some new seeder classes. The cached configurations didn't recognize the new classes. So running that command again worked.
我遇到了这个问题,我可以通过执行php artisan config:cache
. 问题是我之前已经运行过该命令,后来又包含了一些新的播种机类。缓存的配置无法识别新类。所以再次运行该命令有效。
If you see yourself making frequent changes to include new seeder classes then consider running php artisan config:clear
. This will enable you to make as many changes as you'd like and then after testing you can run config:cache
again to make things run optimally again.
如果您发现自己经常更改以包含新的播种机类,请考虑运行php artisan config:clear
. 这将使您能够根据需要进行任意数量的更改,然后在测试之后您可以config:cache
再次运行以使事情再次以最佳方式运行。
回答by Fazil Raza
Check your capitalization!
检查您的大小写!
Your host system (Windows or Mac) is case insensitive by default, and Homestead inherits this behavior. Your production server on the other hand is case sensitive.
你的主机系统(Windows 或 Mac)默认不区分大小写,Homestead 继承了这个行为。另一方面,您的生产服务器区分大小写。
Whenever you get a ClassNotFoundException check the following:
每当您收到ClassNotFound异常时,请检查以下内容:
- Spelling
- Namespaces
- Capitalization
- 拼写
- 命名空间
- 大写
回答by Manpreet
If the issue is not resolved by composer dump-autoload
or is not a newly created class.
如果问题未由composer dump-autoload
新创建的类解决或不是新创建的类。
Check for syntax errors in your class and its traits as well.
In my case, there was a syntax error in a Trait, but ReflectionException
was shown for the actual Class using that Trait instead.
检查您的类及其特征中的语法错误。就我而言,Trait 中存在语法错误,但ReflectionException
显示为使用该 Trait 的实际类。
回答by easycodingclub
try to use following command
尝试使用以下命令
php artisan db:seed --class=DatabaseSeeder
回答by G-Man
You need to assign it to a name space for it to be found.
您需要将它分配给一个名称空间才能找到它。
namespace App\Http\Controllers;