#3 telah kemaskini category

This commit is contained in:
pesu98
2026-05-12 10:41:18 +08:00
parent 53be5221e9
commit e99bd19035
15 changed files with 668 additions and 25 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace Database\Factories;
use App\Models\Category;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<Category>
*/
class CategoryFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$name = fake()->unique()->words(2, true);
return [
'name' => Str::title($name),
'slug' => Str::slug($name),
'description' => fake()->sentence(),
'color' => fake()->hexColor(),
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->string('color', 7)->default('#4f46e5');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('categories');
}
};

View File

@@ -0,0 +1,29 @@
<?php
namespace Database\Seeders;
use App\Models\Category;
use Illuminate\Database\Seeder;
class CategorySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$categories = [
['name' => 'Product Updates', 'slug' => 'product-updates', 'description' => 'Announcements and release notes.', 'color' => '#4f46e5'],
['name' => 'Operations', 'slug' => 'operations', 'description' => 'Internal workflow and process items.', 'color' => '#10b981'],
['name' => 'Marketing', 'slug' => 'marketing', 'description' => 'Campaigns, content, and promotions.', 'color' => '#f59e0b'],
['name' => 'Support', 'slug' => 'support', 'description' => 'Customer support and service categories.', 'color' => '#ec4899'],
];
foreach ($categories as $category) {
Category::query()->updateOrCreate(
['slug' => $category['slug']],
$category,
);
}
}
}

View File

@@ -17,6 +17,8 @@ class DatabaseSeeder extends Seeder
{
// User::factory(10)->create();
$this->call(CategorySeeder::class);
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',