[SeederPelanggan]

This commit is contained in:
Arief Dwi Wicaksono 2025-10-09 11:39:47 +07:00
parent 7598b2d3eb
commit 472f385b65
3 changed files with 66 additions and 2 deletions

View File

@ -26,19 +26,21 @@ class Template extends Model
'harga' => 'decimal:2',
];
protected $appends = ['slug'];
// Relasi ke Kategori
public function kategori()
{
return $this->belongsTo(Kategori::class, 'kategori_id');
}
// Relasi ke Pelanggan (jika kamu mau tahu siapa saja pesan template ini)
// Relasi ke Pelanggan
public function pelanggans()
{
return $this->hasMany(Pelanggan::class, 'template_id');
}
// Accessor untuk slug berdasarkan nama_template
// Accessor untuk slug
public function getSlugAttribute()
{
return Str::slug($this->nama_template);

View File

@ -12,6 +12,7 @@ class DatabaseSeeder extends Seeder
$this->call([
TemplateSeeder::class,
AdminSeeder::class,
PelangganSeeder::class,
]);
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Pelanggan;
use Illuminate\Support\Str;
class PelangganSeeder extends Seeder
{
public function run(): void
{
// contoh beberapa pelanggan
$pelanggans = [
[
'nama_pemesan' => 'Arief Dwi Wicaksono',
'email' => 'arief@example.com',
'no_tlpn' => '081234567890',
'template_id' => 1, // pastikan ada template_id valid
'form' => json_encode([
'nama_pria' => 'Arief',
'nama_wanita' => 'Nisa',
'alamat' => 'Malang',
]),
'harga' => 150000,
'status' => 'menunggu',
],
[
'nama_pemesan' => 'Rizky Ramadhan',
'email' => 'rizky@example.com',
'no_tlpn' => '081298765432',
'template_id' => 2,
'form' => json_encode([
'nama_pria' => 'Rizky',
'nama_wanita' => 'Dinda',
'alamat' => 'Surabaya',
]),
'harga' => 250000,
'status' => 'diterima',
],
[
'nama_pemesan' => 'Siti Rahmawati',
'email' => 'siti@example.com',
'no_tlpn' => '081212341234',
'template_id' => 3,
'form' => json_encode([
'nama_pria' => 'Andi',
'nama_wanita' => 'Siti',
'alamat' => 'Jakarta',
]),
'harga' => 300000,
'status' => 'menunggu',
],
];
foreach ($pelanggans as $data) {
$data['invitation_code'] = 'INV-' . strtoupper(Str::random(6)); // 🟢 generate code unik
Pelanggan::create($data);
}
}
}