0
votes

I want to seed users to database but seeder doesn't create password.

I have This migration File

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('email')->unique();
        $table->string('username');
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('users');
}

}

and this Seeder file

// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;

class UsersTableSeeder extends Seeder {

    public function run()
    {
        $faker = Faker::create();

        DB::table('users')->truncate();

        foreach(range(1, 3) as $index)
        {
            $user = User::create(array(
                'password' => $faker->word,
                'username' => $faker->userName,
                'email' => $faker->email
            ));
        }


    }

}

I did php artisan migrate and it said "nothing to migrate"

so now when I do php artisan db:seed --class=UsersTableSeeder it throws no error.

Any idea why seeder does not create username? I have just empty column in my database...

thank you very much for any help.

1
Tried adding Eloquent::unguard(); before the start of the foreach loop? Also, migration (php artisan migrate command) is only concerned with running the migrations (creating the database not populating). Alternately you can include on your DatabaseSeeder $this->call('UsersTableSeeder'); then you can run php artisan migrate --seed - lozadaOmr
That helped :) post it like a answe so i can rate it :) - Jakub Kohout

1 Answers

3
votes

Try adding Eloquent::unguard(); before the start of the foreach() loop.


Also, migration (php artisan migrate command) is only concerned with running the migrations (creating the database not populating).

Alternately you can include on your DatabaseSeeder $this->call('UsersTableSeeder'); then you can run php artisan migrate --seed