jeudi 16 juin 2016

Laravel 5.1 - Model Factory Error seed

Hi i'm trying to populate my database with some Articles, BlogCategories, Users.

when i do "php artisan db:seed" i have this error:

[ErrorException] Argument 2 passed to Illuminate\Database\Eloquent\Factory::define() must be callable. string given, called in C:\xampp\htdocs\2016\database\factories\ModelFactory.php on line 22 and defined

I inserted all relations in my models and i done my migrations good!

ModelFactory.php

$factory->define(dixard\User::class, 'admin', function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->safeEmail,
        'password' => bcrypt('123'),
        'user_type' => 3,
        'remember_token' => str_random(10),
    ];
}); // line 22 

$factory->define(dixard\User::class, 'member', function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->safeEmail,
        'password' => bcrypt('123'),
        'user_type' => 1,
        'remember_token' => str_random(10),
    ];
});

$factory->define(dixard\BlogCategory::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->word,
    ];
});

$factory->define(dixard\Article::class, function (Faker\Generator $faker) {
    return [
        'title' => $faker->sentence,
        'content' => $faker->paragraph,
        'tags' => $faker->word,
        'user_id' => dixard\User::all()->random()->id,
        'category_id' => dixard\BlogCategory::all()->random()->id,
    ];
});

user_type can be 0 (customer), 1(artist), 3(admin) is a bolean field.

databaseSeeder.php

public function run()
    {
        Model::unguard();

        factory('dixard\User','admin', 3)->create();
        factory('dixard\BlogCategory', 5)->create();
        factory('dixard\Article', 20)->create();


        // $this->call(UserTableSeeder::class);
        $this->call(CategoryTableSeeder::class);
        $this->call(GenderTableSeeder::class);
        $this->call(ProductTableSeeder::class);
        $this->call(ColorTableSeeder::class);
        $this->call(BalanceTableSeeder::class);
        $this->call(ShippingsTableSeeder::class);
        $this->call(CouponTableSeeder::class);

        Model::reguard();
    }

Thank you for your help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire