Laravel的db:seed没有在数据库中插入任何记录

时间:2018-02-15 10:08:47

标签: laravel laravel-5 factory faker

我正在使用Laravel 5.6并且数据库播种器无法正常工作。我试图在我的数据库中插入100个新数据,但没有插入任何内容。没有显示错误,我也不知道为什么DatabaseSeeder.php无效

这是我的<?php use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { public function run() { $students = factory(App\Student::class, 100)->make(); } }

StudentFactory.php

这是我的use Faker\Generator as Faker; $factory->define(App\Student::class, function (Faker $faker) { return [ 'id' => $faker->unique()->numberBetween(1,1000), 'rfid_number' => $faker->unique()->numberBetween(1,1000), 'first_name' => $faker->firstName, 'middle_name' => $faker->lastName, 'last_name' => $faker->lastName, 'name_extension' => $faker->suffix, 'email' => $faker->safeEmail, 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret 'photo' => '', 'house_number' => $faker->buildingNumber, 'barangay' => $faker->streetName, 'city' => $faker->city, 'province' => $faker->state, 'zip_code' => $faker->postCode, 'birth_date' => $faker->date('Y-m-d'), 'birth_place' => $faker->streetAddress, 'gender' => 'Male', 'religion' => 'Roman Catholic', 'landline_number' => $faker->tollFreePhoneNumber, 'mobile_number' => $faker->tollFreePhoneNumber, 'father_name' => $faker->name, 'father_occupation' => $faker->jobTitle, 'mother_name' => $faker->name, 'mother_occupation' => $faker->jobTitle, 'guardian_name' => $faker->name, 'guardian_occupation' => $faker->jobTitle, 'guardian_address' => $faker->streetAddress, 'year' => $faker->numberBetween(1,6), 'section' => $faker->cityPrefix, 'created_at' => now(), 'updated_at' => now() ]; });

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.A)
    {
        MessageBox.Show("Hello");
    }
}

并且没有显示错误。

1 个答案:

答案 0 :(得分:3)

使用create()方法:

$students = factory(App\Student::class, 100)->create();