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

标签 php laravel

获取错误:

[无效参数异常]
命令“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/

相关文章:

php - 从 PHP 调用存储过程,使用 PHP 变量作为 IN 参数

php - 如果我成功连接后,有效的 mysql 查询会失败吗?

php - 500 内部错误 : Failed to load resource Laravel 5. 0

php - 调用数组 laravel 上的成员函数 where()

php - React Fetch 到 Laravel API 创建新 session

Laravel 5.6 验证 required_without 多个

php - 如何使用两个查询结果只显示一次数据

Nginx php-fpm 子目录

php - 博客中的文章作者不显示

mysql - Laravel 5.3 查询 - 具有投票总和的不同结果