Skip to content

Instantly share code, notes, and snippets.

@NandoKstroNet
Created January 13, 2022 22:10
Show Gist options
  • Save NandoKstroNet/dd1e1610b477e38c140b8641ce8f8c67 to your computer and use it in GitHub Desktop.
Save NandoKstroNet/dd1e1610b477e38c140b8641ce8f8c67 to your computer and use it in GitHub Desktop.
Factories e Seed Tenant Store em https://codeexperts.com.br
<?php
\App\Models\Tenant::factory(10)
->hasStores(1)
->create();
foreach(\App\Models\Store::all() as $store) {
$tenantAndStoreIds = ['store_id' => $store->id, 'tenant_id' => $store->tenant_id];
\App\Models\Product::factory(20, $tenantAndStoreIds)
->create();
}
<?php
//tenant factory
'contract' => $this->faker->uuid,
'is_active' => 1
//store factory
'name' => $this->faker->word,
'description' => $this->faker->sentence,
'logo' => $this->faker->imageUrl(180, 180),
'cover' => $this->faker->imageUrl(1280, 720),
'subdomain' => $this->faker->slug
//product factory
$nameProduct = $this->faker->word;
return [
'name' => $nameProduct,
'description' => $this->faker->sentence,
'price' => $this->faker->numberBetween(1, 5000),
'body' => $this->faker->paragraphs(5, true),
'slug' => Str::slug($nameProduct)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment