Commit 241193f5 authored by TTS Tran Viet Anh's avatar TTS Tran Viet Anh

seeding database

parent 86316bdc
<?php
namespace Database\Factories;
use App\Models\PostCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
class PostCategoryFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->sentence(1),
'image' => $this->faker->imageUrl(80, 640, 'Post category', true),
'parent_id' => rand(0, 1) ? null : rand(1, 10),
'status' => PostCategory::STATUS_ENABLE,
'ordering' => rand(1, 3),
];
}
}
<?php
namespace Database\Factories;
use App\Models\Post;
use App\Models\PostCategory;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class PostFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'title' => $this->faker->sentence(),
'content' => $this->faker->paragraph(),
'image' => $this->faker->imageUrl(640, 480, 'post', true),
'user_id' => User::inRandomOrder()->first()->id ?? null,
'post_category_id' => PostCategory::inRandomOrder()->first()->id ?? null,
'publish_date' => $this->faker->date(),
'status' => Post::STATUS_PUBLISHED,
];
}
}
<?php
namespace Database\Factories;
use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductAttributeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'size' => $this->faker->randomElement(['S', 'M', 'L', 'XL']),
'color' => $this->faker->safeColorName(),
'quantity' => $this->faker->numberBetween(0, 100),
'product_id' => Product::inRandomOrder()->first()->id ?? null,
];
}
}
<?php
namespace Database\Factories;
use App\Models\ProductCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductCategoryFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->sentence(1),
'image' => $this->faker->imageUrl(80, 640, 'product category', true),
'parent_id' => rand(0, 1) ? null : rand(1, 10),
'status' => ProductCategory::STATUS_ENABLE,
'ordering' => rand(1, 3),
];
}
}
<?php
namespace Database\Factories;
use App\Models\Product;
use App\Models\ProductCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->sentence(2),
'image' => $this->faker->imageUrl(480, 640, 'products', true),
'description' => $this->faker->paragraph(2),
'price' => $this->faker->randomFloat(2, 10, 200),
'product_category_id' => ProductCategory::inRandomOrder()->first()->id ?? null,
'stock' => $this->faker->numberBetween(0, 200),
'status' => Product::STATUS_ENABLE,
];
}
}
...@@ -17,6 +17,8 @@ public function definition() ...@@ -17,6 +17,8 @@ public function definition()
return [ return [
'name' => $this->faker->name(), 'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(), 'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->phoneNumber(),
'address' => $this->faker->address(),
'email_verified_at' => now(), 'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10), 'remember_token' => Str::random(10),
......
...@@ -13,6 +13,11 @@ class DatabaseSeeder extends Seeder ...@@ -13,6 +13,11 @@ class DatabaseSeeder extends Seeder
*/ */
public function run() public function run()
{ {
// \App\Models\User::factory(10)->create(); \App\Models\PostCategory::factory(5)->create();
\App\Models\ProductCategory::factory(5)->create();
\App\Models\User::factory(5)->create();
\App\Models\Post::factory(10)->create();
\App\Models\Product::factory(10)->create();
\App\Models\ProductAttribute::factory(50)->create();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment