Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated factory return an empty array #16

Closed
onlyu-bot opened this issue Jul 13, 2020 · 2 comments
Closed

Generated factory return an empty array #16

onlyu-bot opened this issue Jul 13, 2020 · 2 comments

Comments

@onlyu-bot
Copy link

Hi, this is my first time using this package, and it generated a factory which return an empty array.

The Product model:

namespace App\Models\Product;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $connection = 'sqlite_product';
}

The migration:

Schema::connection('sqlite_product')->create('products', function (Blueprint $table) {
    $table->tinyIncrements('id')->index();
    $table->string('name');
    $table->unsignedSmallInteger('price');
    $table->boolean('is_public')->default(true);
}

After php artisan migrate, and then php artisan make:populated-factory Models\\Product\\Product, there was a message Populated "ProductFactory" factory for "Product" model has been created successfully!

But the ProductFactory return an empty array

use Faker\Generator as Faker;

/** @var \Illuminate\Database\Eloquent\Factory $factory */

$factory->define(\App\Models\Product\Product::class, function (Faker $faker) {
    return [
    ];
});

I was hoping to generate something like

use Faker\Generator as Faker;

/** @var \Illuminate\Database\Eloquent\Factory $factory */

$factory->define(\App\Models\Product\Product::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'price' => $faker->randomNumber(),
        'is_public' => $faker->boolean()
    ];
});

I don't know why, my Laravel Framework is 7.19.0, please help, thank you.

@onlyu-bot
Copy link
Author

I found that the FactoryGenerator class use the default DB connection to generate factory instead of the model's connection, so I open a PR #17 to fix it.

@hivokas
Copy link
Member

hivokas commented Sep 9, 2020

@onlyu-bot fixed in 1.0.0 release

@hivokas hivokas closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants