Testes

Criação de Factory

​php artisan make:factory CompanyFactory --model=Company​

     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Company::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'category_id' => Category::factory()->create(),
            'name' => $this->faker->unique()->name(),
            'email' => $this->faker->unique()->email(),
            'whatsapp' => $this->faker->unique()->numberBetween(1000000000, 99999999999),
            'image' => 'eti.png',
        ];
    }


para testar podemos utilizar o tinker

php artisan tinker

\\App\Models\Company::factory(0->create();

Para rodar via seeders

php artisan db:seed --class=ProductsTableSeeder

Você achou esse artigo útil?