gpt4 book ai didi

php - 命令 "make:seeder"未在 laravel 5.0 中定义

转载 作者:搜寻专家 更新时间:2023-10-31 20:35:13 25 4
gpt4 key购买 nike

获取错误:

[无效参数异常]
命令“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 the DatabaseSeeder 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 as UserTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call 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-autoloadcomposer dumpautoload(它的作用相同,但只是另一个名称)。

关于php - 命令 "make:seeder"未在 laravel 5.0 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com