DemoSeeder — GoldenStreet Property

Laravel 13 · 3 user · 5 tipe properti · 10 properti · 6 amenity · 2 kuota · 6 setting

Ringkasan

DemoSeeder membuat data demo realistis untuk testing & demo live.

DataJumlah
Roles5 (seeker, owner, agent, admin, super_admin)
Users3 (super admin, owner, seeker)
Property types5 (rumah, ruko, apartemen, kavling, sawah)
Amenities6
Settings6 (theme, brand, moderasi, contact)
Role quotas2 (owner, agent)
Properties10 (campuran tanah & bangunan, jual & sewa)

Cara Jalankan

php artisan db:seed

Atau khusus DemoSeeder:

php artisan db:seed --class=DemoSeeder
Jangan jalankan --seed di produksi jika tidak ingin data demo. Untuk produksi: php artisan migrate, lalu buat admin via tinker.

Login Demo

RoleEmailPassword
Super Adminsuperadmin@example.compassword
Ownerowner@example.compassword
Seekerseeker@example.compassword

File

database/seeders/DemoSeeder.php

Isi File

<?php

namespace Database\Seeders;

use App\Models\Amenity;
use App\Models\Property;
use App\Models\PropertyPrice;
use App\Models\PropertyType;
use App\Models\RoleListingQuota;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Spatie\Permission\Models\Role;

class DemoSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Roles
        foreach (['seeker', 'owner', 'agent', 'admin', 'super_admin'] as $r) {
            Role::firstOrCreate(['name' => $r]);
        }

        // 2. Super Admin
        $admin = User::firstOrCreate(
            ['email' => 'superadmin@example.com'],
            [
                'name' => 'Super Admin',
                'password' => bcrypt('password'),
                'role' => 'super_admin',
                'is_verified' => true,
                'status' => 'active',
            ]
        );
        $admin->assignRole('super_admin');

        // 3. Owner
        $owner = User::firstOrCreate(
            ['email' => 'owner@example.com'],
            [
                'name' => 'Demo Owner',
                'password' => bcrypt('password'),
                'role' => 'owner',
                'is_verified' => true,
                'status' => 'active',
            ]
        );
        $owner->assignRole('owner');

        // 4. Seeker
        $seeker = User::firstOrCreate(
            ['email' => 'seeker@example.com'],
            [
                'name' => 'Demo Seeker',
                'password' => bcrypt('password'),
                'role' => 'seeker',
                'is_verified' => true,
                'status' => 'active',
            ]
        );
        $seeker->assignRole('seeker');

        // 5. Master data
        $types = [
            ['code' => 'rumah', 'name' => 'Rumah', 'category' => 'building'],
            ['code' => 'ruko', 'name' => 'Ruko', 'category' => 'building'],
            ['code' => 'apartemen', 'name' => 'Apartemen', 'category' => 'building'],
            ['code' => 'kavling', 'name' => 'Kavling', 'category' => 'land'],
            ['code' => 'sawah', 'name' => 'Sawah', 'category' => 'land'],
        ];
        foreach ($types as $t) {
            PropertyType::firstOrCreate(['code' => $t['code']], $t + ['is_active' => true]);
        }

        $amenities = ['Parkir', 'Listrik', 'Air', 'Furnished', 'Akses Jalan', 'Keamanan'];
        foreach ($amenities as $a) {
            Amenity::firstOrCreate(['name' => $a], ['code' => Str::slug($a), 'applies_to' => 'both']);
        }

        // 6. Settings
        $settings = [
            ['key' => 'theme.active', 'value' => 'default', 'group' => 'theme'],
            ['key' => 'brand.name', 'value' => 'GoldenStreet Properti', 'group' => 'brand'],
            ['key' => 'brand.tagline', 'value' => 'Jual, sewa, kontrakan tanpa ribet', 'group' => 'brand'],
            ['key' => 'property.require_moderation', 'value' => '1', 'group' => 'property'],
            ['key' => 'contact.email', 'value' => 'halo@goldenstreet.test', 'group' => 'contact'],
            ['key' => 'contact.whatsapp', 'value' => '6281234567890', 'group' => 'contact'],
        ];
        foreach ($settings as $s) {
            Setting::updateOrCreate(['key' => $s['key']], $s);
        }

        // 7. Quota
        RoleListingQuota::updateOrCreate(['role' => 'owner'], ['max_active_listings' => 10]);
        RoleListingQuota::updateOrCreate(['role' => 'agent'], ['max_active_listings' => 50]);

        // 8. Demo properties (10)
        $demo = [
            ['title' => 'Rumah Modern 2 Lantai di Bandung', 'type' => 'rumah', 'transaction' => 'sale', 'city' => 'Bandung', 'province' => 'Jawa Barat', 'land' => 120, 'building' => 90, 'bed' => 3, 'bath' => 2, 'price' => 1200000000, 'period' => 'sale'],
            ['title' => 'Ruko Strategis di Jakarta Selatan', 'type' => 'ruko', 'transaction' => 'sale', 'city' => 'Jakarta Selatan', 'province' => 'DKI Jakarta', 'land' => 80, 'building' => 160, 'bed' => 0, 'bath' => 2, 'price' => 3500000000, 'period' => 'sale'],
            ['title' => 'Apartemen Studio di Surabaya', 'type' => 'apartemen', 'transaction' => 'rent', 'city' => 'Surabaya', 'province' => 'Jawa Timur', 'land' => 0, 'building' => 30, 'bed' => 1, 'bath' => 1, 'price' => 2500000, 'period' => 'monthly'],
            ['title' => 'Kavling Siap Bangun di Bogor', 'type' => 'kavling', 'transaction' => 'sale', 'city' => 'Bogor', 'province' => 'Jawa Barat', 'land' => 200, 'building' => 0, 'bed' => 0, 'bath' => 0, 'price' => 450000000, 'period' => 'sale'],
            ['title' => 'Sawah Produktif di Sleman', 'type' => 'sawah', 'transaction' => 'sale', 'city' => 'Sleman', 'province' => 'DI Yogyakarta', 'land' => 1000, 'building' => 0, 'bed' => 0, 'bath' => 0, 'price' => 800000000, 'period' => 'sale'],
            ['title' => 'Rumah Minimalis di Tangerang', 'type' => 'rumah', 'transaction' => 'rent', 'city' => 'Tangerang', 'province' => 'Banten', 'land' => 90, 'building' => 70, 'bed' => 2, 'bath' => 1, 'price' => 4500000, 'period' => 'monthly'],
            ['title' => 'Ruko Baru di Semarang', 'type' => 'ruko', 'transaction' => 'rent', 'city' => 'Semarang', 'province' => 'Jawa Tengah', 'land' => 60, 'building' => 120, 'bed' => 0, 'bath' => 1, 'price' => 3500000, 'period' => 'monthly'],
            ['title' => 'Apartemen 2BR di Bekasi', 'type' => 'apartemen', 'transaction' => 'rent', 'city' => 'Bekasi', 'province' => 'Jawa Barat', 'land' => 0, 'building' => 55, 'bed' => 2, 'bath' => 1, 'price' => 3500000, 'period' => 'monthly'],
            ['title' => 'Rumah Hook di Denpasar', 'type' => 'rumah', 'transaction' => 'sale', 'city' => 'Denpasar', 'province' => 'Bali', 'land' => 150, 'building' => 110, 'bed' => 3, 'bath' => 2, 'price' => 1800000000, 'period' => 'sale'],
            ['title' => 'Kavling Murah di Depok', 'type' => 'kavling', 'transaction' => 'sale', 'city' => 'Depok', 'province' => 'Jawa Barat', 'land' => 100, 'building' => 0, 'bed' => 0, 'bath' => 0, 'price' => 300000000, 'period' => 'sale'],
        ];

        foreach ($demo as $i => $d) {
            $type = PropertyType::where('code', $d['type'])->first();
            $slug = Str::slug($d['title']) . '-' . ($i + 1);

            $property = Property::firstOrCreate(
                ['slug' => $slug],
                [
                    'owner_id' => $owner->id,
                    'property_type_id' => $type->id,
                    'object_category' => $type->category,
                    'transaction_type' => $d['transaction'],
                    'title' => $d['title'],
                    'description' => "Properti demo: {$d['title']}. Lokasi strategis, cocok untuk investasi maupun hunian.",
                    'province' => $d['province'],
                    'city' => $d['city'],
                    'district' => 'Kecamatan Demo',
                    'address' => 'Jl. Demo No. ' . ($i + 1),
                    'latitude' => -6.2 + ($i * 0.05),
                    'longitude' => 106.8 + ($i * 0.05),
                    'land_area' => $d['land'],
                    'building_area' => $d['building'],
                    'bedrooms' => $d['bed'],
                    'bathrooms' => $d['bath'],
                    'floors' => $d['building'] > 0 ? 2 : 0,
                    'certificate' => 'SHM',
                    'furnishing' => $d['building'] > 0 ? 'semi' : null,
                    'utilities_included' => true,
                    'status' => 'active',
                    'is_verified' => true,
                    'published_at' => now(),
                    'expires_at' => now()->addDays(90),
                ]
            );

            PropertyPrice::updateOrCreate(
                ['property_id' => $property->id, 'period' => $d['period']],
                ['price' => $d['price'], 'is_active' => true]
            );
        }

        $this->command->info('DemoSeeder selesai: 3 user, 5 tipe, 10 properti, 6 amenity, 2 kuota, 6 setting.');
    }
}