获取错误:
[无效参数异常]
命令“make:seeder”未定义。
您是指其中之一吗?
数据库:种子
制作:迁移
制作: Controller
使:中间件
制作:请求
制作:提供者
制作:控制台
制作:事件
品牌:型号
制作:命令
我的 laravel 版本是 5.0。我已经运行了 php artisan make:seeder SettingTableSeeder。
最佳答案
php artisan make:seeder
命令是在 Laravel 5.1 中引入的,因此在 Laravel 5.0 中将无法使用
您需要运行另一个命令:
To seed your database, you may use the
db:seed
command on the Artisan CLI:php artisan db:seed
By default, the
db:seed
command runs theDatabaseSeeder
class, which may be used to call other seed classes. However, you may use the--class
option to specify a specific seeder class to run individually:php artisan db:seed --class=UserTableSeeder
You may also seed your database using the
migrate:refresh
command, which will also rollback and re-run all of your migrations:php artisan migrate:refresh --seed
摘自 Laravel 文档: https://laravel.com/docs/5.0/migrations#database-seeding
如何创建种子
Laravel also includes a simple way to seed your database with test data using seed classes. All seed classes are stored in
database/seeds
. Seed classes may have any name you wish, but probably should follow some sensible convention, such asUserTableSeeder
, etc. By default, aDatabaseSeeder
class is defined for you. From this class, you may use thecall
method to run other seed classes, allowing you to control the seeding order.
将其添加到 database/seeds/seedsfilename.php
中的文件中。
class DatabaseSeeder extends Seeder {
public function run()
{
$this->call('UserTableSeeder');
$this->command->info('User table seeded!');
}
}
class UserTableSeeder extends Seeder {
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'foo@bar.com']);
}
}
之后您需要运行 composer dump-autoload
或 composer dumpautoload
(它的作用相同,但只是另一个名称)。
关于php - 命令 "make:seeder"未在 laravel 5.0 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408050/