Skip to content

Generated factory return an empty array #16

@onlyu-bot

Description

@onlyu-bot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions