问题描述
所以我在laravel 6.1中创建了一个播种器,但我一直收到此错误Illuminate \ Contracts \ Container \ BindingResolutionException:目标类[AdminsTableSeeder]不存在.我尝试运行composer dump-autoload和composer dumpautoload,这些解决方案我在Internet上到处都可以找到,但是不知何故,它对我不起作用.任何人都可以帮助解决此错误.在过去的两个小时中,我一直在尝试解决此错误,我们将非常感谢您的帮助.此外,我对laravel还是陌生的.这是我的AdminsTableSeeder.php
so I am creating a seeder in laravel 6.1 but I keep getting this error Illuminate\Contracts\Container\BindingResolutionException : Target class [AdminsTableSeeder] does not exist. I tried running composer dump-autoload and composer dumpautoload, the solutions that I had found everywhere on the internet but somehow, it doesnt work for me. Could anybody please help resolve this error. I have been trying to resolve this bug for the past two hours, help would be immensely appreciated.Also, I am fairly new to laravel.here is my AdminsTableSeeder.php
use App\Models\Admin;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
class AdminsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
Admin::create([
'name' => $faker->name,
'email' => '[email protected]',
'password' => bcrypt('password'),
]);
}
}
这是我的DatabaseSeeder.php
and here is my DatabaseSeeder.php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(AdminsTableSeeder::class);
}
}
推荐答案
请确保您的 AdminsTableSeeder.php
文件与您的 DatabaseSeeder.php
位于同一目录中文件.
Make sure your AdminsTableSeeder.php
file is in the same directory where you have your DatabaseSeeder.php
file.
运行
composer dump-autoload
然后尝试
php artisan db:seed
可选.
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run(){
$this->call('AdminsTableSeeder');
}
}
尝试使用 $ this-> call('AdminsTableSeeder');
这样.
这篇关于获取Illuminate \ Contracts \ Container \ BindingResolutionException:目标类[AdminsTableSeeder]不存在.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!