可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
As soon, I am typing php artisan db:seed
command.
I'm getting Error Like:
[ReflectionException]
Class UserTableSeeder does not exist
root@dd-desktop:/opt/lampp/htdocs/dd/laravel# php artisan db:seed
Here, Is my UserTableSeeder.php
& DatabaseSeeder.php
Page
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' => 'chris@scotch.io',
'password' => Hash::make('awesome'),
));
}
}
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//Model::unguard();
Eloquent::unguard();
$this->call('UserTableSeeder');
//$this->call(UserTableSeeder::class);
//Model::reguard();
}
}
I'm Referring This Link To Design & Develop Login Page.
Please Help me to resolve this issue. Thanks.
回答1:
Perform a composer update
, then 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:
"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!
Edit by @JMSamudio
If composer dump-autoload
is not found, just enable this option composer config -g -- disable-tls true
.
回答2:
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. Please check if the class that is not being reflected can be executed at its own.
回答3:
A composer dump-autoload
should fix it.
回答4:
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.
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.
回答5:
I have the same problem with a class
. I try composer dump-autoload
and php artisan config:clear
but not solve my problem.
Then i decided read my code to find anything problem, ain i find the problem. The problem in my case is only comma missing on 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'
];
}
回答6:
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.
回答7:
try to use following command
php artisan db:seed --class=DatabaseSeeder
回答8:
You need to assign it to a name space for it to be found.
namespace App\Http\Controllers;
回答9:
I am not writing as the answer for this question. But I want to help others if they faced the same bug but the answers mentioned here not works. I also tried all the solutions mentioned here. But my problem was with the namespace I used. The path was wrong.
The namespace I used is:
namespace App\Http\Controllers;
But actually the controller reside inside a folder named 'FrontEnd'
so the solution is change the namespace to:
namespace App\Http\Controllers\Frontend;
回答10:
When it is looking for the seeder class file, you can run composer dump-autoload. When you run it again and it's looking for the Model, you can reference it on the seeder file itself. Like so,
use App\{Model};
回答11:
Not strictly related to the question but received the error ReflectionException: Class config does not exist
I had added a new .env
variable with spaces in it. Running php artisan config:clear
told me that any .env
variable with spaces in it should be surrounded by "
s.
Did this and my application stated working again, no need for config clear as still in development on Laravel Homestead (5.4)
回答12:
I've recreated class, and it worked. Copy all file content, delete file, and run php artisan make:seeder ModelTableSeeder
. Because composer dump-autoload
didn't worked for me.
回答13:
You may try to write app
in use
uppercase, so App
. Worked for me.
回答14:
composer dump-autoload
this will fix it
回答15:
composer update
Above Command work for me.
Whenever you make new migration in la-ravel you need to refresh "classmap" in composer.json file .