我已经签出,类PermissionsTableSeeder
通过以下路径存在:Database\Seeds\PermissionsTableSeeder
。
我也尝试过:
composer dump-autoload
php artisan cache:clear
当我运行命令:php artisan db:seed
时,它给了我一个例外:
ReflectionException:类数据库\种子\ PermissionsTableSeeder 不存在
在C:\ Projects \ secure_secure \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ Container.php:790 786 | if($ concrete instanceof Closure){ 787 |返回$ concrete($ this,$ this-> getLastParameterOverride()); 788 | } 789 |
790 | $ reflector = new ReflectionClass($ concrete); 791 | 792 | //如果类型不可实例化,则开发人员正在尝试解析 793 | //抽象类型,例如Interface或Abstract Class, 794 | //没有为抽象注册任何绑定,因此我们需要纾困。
异常跟踪:
1
ReflectionClass :: __ construct(“ Database \ Seeds \ PermissionsTableSeeder”) C:\ Projects \ secure_secure \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ Container.php:7902
Illuminate \ Container \ Container :: build(“ Database \ Seeds \ PermissionsTableSeeder”) C:\ Projects \ secure_secure \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ Container.php:667
如何解决?
答案 0 :(得分:2)
laravel中没有Database\Seeds\
命名空间,默认情况下,种子节点没有命名空间。
请检查DatabaseSeeder.php
您应该具有此功能:
public function run()
{
.....
$this->call(PermissionsTableSeeder::class);
}
还要检查您是否没有为DatabaseSeeder
类或PermissionsTableSeeder
类赋予任何命名空间。
您还应该删除use Database\Seeds
中以DatabaseSeeder.php
开头的任何行,因为该命名空间不存在。
答案 1 :(得分:0)
我更改了database/seeds/DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Database\Seeds\PermissionsTableSeeder;
use Database\Seeds\RolesTableSeeder;
use Database\Seeds\ConnectRelationshipsSeeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call(PermissionsTableSeeder::class);
$this->call(RolesTableSeeder::class);
$this->call(ConnectRelationshipsSeeder::class);
//$this->call('UsersTableSeeder');
Model::reguard();
}
}
到
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Database\Seeds\PermissionsTableSeeder;
use Database\Seeds\RolesTableSeeder;
use Database\Seeds\ConnectRelationshipsSeeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('PermissionsTableSeeder');
$this->call('RolesTableSeeder');
$this->call('ConnectRelationshipsSeeder');
//$this->call('UsersTableSeeder');
Model::reguard();
}
}
这解决了我的错误
php artisan db:seed
Seeding: DefaultPermissionitemsTableSeeder
Seeding: DefaultRoleItemsTableSeeder
Seeding: DefaultConnectRelationshipsSeeder
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:view.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:create.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:edit.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:delete.users
Seeding: PermissionsTableSeeder
ReflectionException : Class Database\Seeds\RolesTableSeeder does not exist
at D:\Work\Coding\Laravel\Epox\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
784| if ($concrete instanceof Closure) {
785| return $concrete($this, $this->getLastParameterOverride());
786| }
787|
> 788| $reflector = new ReflectionClass($concrete);
789|
790| // If the type is not instantiable, the developer is attempting to resolve
791| // an abstract type such as an Interface or Abstract Class and there is
792| // no binding registered for the abstractions so we need to bail out.
Exception trace:
1 ReflectionClass::__construct("Database\Seeds\RolesTableSeeder")
D:\Work\Coding\Laravel\Epox\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
2 Illuminate\Container\Container::build("Database\Seeds\RolesTableSeeder")
D:\Work\Coding\Laravel\Epox\vendor\laravel\framework\src\Illuminate\Container\Container.php:667
Please use the argument -v to see more details.
到
php artisan db:seed
Seeding: DefaultPermissionitemsTableSeeder
Seeding: DefaultRoleItemsTableSeeder
Seeding: DefaultConnectRelationshipsSeeder
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:view.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:create.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:edit.users
Seeding: DefaultConnectRelationshipsSeeder - Role:Admin attached to Permission:delete.users
Seeding: PermissionsTableSeeder
Seeding: RolesTableSeeder
Seeding: ConnectRelationshipsSeeder
php artisan --version
Laravel Framework 5.8.36