- membuat class enum IsShow - menyesuaikan seeder - menambahkan input kolom baru ke form - membuat handle crud nya
128 lines
4.5 KiB
PHP
128 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\VoucherType;
|
|
use App\Models\Outlet;
|
|
use App\Models\Voucher;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class VoucherSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$vouchers = [
|
|
[
|
|
'name' => 'Diskon 10%',
|
|
'code' => 'DISC10',
|
|
'type' => VoucherType::PERCENTAGE,
|
|
'tags' => 'DISC 10%',
|
|
'summary' => 'Diskon 10% untuk pembelian minimal Rp50.000',
|
|
'discount_amount' => 10,
|
|
'min_purchase' => 50000,
|
|
'max_discount' => 20000,
|
|
'quota' => 100,
|
|
'available_count' => 100,
|
|
'limit_per_user' => 2,
|
|
'start_date' => now()->subDays(5),
|
|
'end_date' => now()->addMonth(),
|
|
],
|
|
[
|
|
'name' => 'Diskon 20%',
|
|
'code' => 'DISC20',
|
|
'type' => VoucherType::PERCENTAGE,
|
|
'tags' => 'DISC 20%',
|
|
'summary' => 'Diskon 20% untuk pembelian minimal Rp100.000',
|
|
'discount_amount' => 20,
|
|
'min_purchase' => 100000,
|
|
'max_discount' => 50000,
|
|
'quota' => 50,
|
|
'available_count' => 50,
|
|
'limit_per_user' => 1,
|
|
'start_date' => now(),
|
|
'end_date' => now()->addDays(30),
|
|
],
|
|
[
|
|
'name' => 'Potongan Rp25K',
|
|
'code' => 'SAVE 25K',
|
|
'type' => VoucherType::FIXED,
|
|
'tags' => 'SAVE 25K',
|
|
'summary' => 'Potongan Rp25K untuk pembelian minimal Rp100.000',
|
|
'discount_amount' => 25000,
|
|
'min_purchase' => 100000,
|
|
'max_discount' => null,
|
|
'quota' => 200,
|
|
'available_count' => 200,
|
|
'limit_per_user' => 3,
|
|
'start_date' => now(),
|
|
'end_date' => now()->addDays(15),
|
|
],
|
|
[
|
|
'name' => 'Potongan Rp50K',
|
|
'code' => 'SAVE50K',
|
|
'type' => VoucherType::FIXED,
|
|
'tags' => 'SAVE 50K',
|
|
'summary' => 'Potongan Rp50K untuk pembelian minimal Rp200.000',
|
|
'discount_amount' => 50000,
|
|
'min_purchase' => 200000,
|
|
'max_discount' => null,
|
|
'quota' => 80,
|
|
'available_count' => 80,
|
|
'limit_per_user' => 1,
|
|
'start_date' => now()->addDays(3),
|
|
'end_date' => now()->addDays(60),
|
|
],
|
|
[
|
|
'name' => 'Gratis Ongkir',
|
|
'code' => 'ONGKIR',
|
|
'type' => VoucherType::FIXED,
|
|
'tags' => 'GRATIS ONGKIR',
|
|
'summary' => 'Gratis Ongkir untuk pembelian minimal Rp50.000',
|
|
'discount_amount' => 15000,
|
|
'min_purchase' => 50000,
|
|
'max_discount' => 15000,
|
|
'quota' => 500,
|
|
'available_count' => 500,
|
|
'limit_per_user' => 5,
|
|
'start_date' => now(),
|
|
'end_date' => now()->addDays(90),
|
|
],
|
|
[
|
|
'name' => 'Flash Sale 30%',
|
|
'code' => 'FLASH30',
|
|
'type' => VoucherType::PERCENTAGE,
|
|
'tags' => 'FLASH 30%',
|
|
'summary' => 'Diskon 30% untuk pembelian minimal Rp75.000',
|
|
'discount_amount' => 30,
|
|
'min_purchase' => 75000,
|
|
'max_discount' => 40000,
|
|
'quota' => 30,
|
|
'available_count' => 30,
|
|
'limit_per_user' => 1,
|
|
'start_date' => now()->subDay(),
|
|
'end_date' => now()->addDay(),
|
|
],
|
|
[
|
|
'name' => 'Spesial Member',
|
|
'code' => 'MEMBER15',
|
|
'type' => VoucherType::PERCENTAGE,
|
|
'tags' => 'Serial Member',
|
|
'summary' => 'Diskon 15% untuk pembelian minimal Rp50.000',
|
|
'discount_amount' => 15,
|
|
'min_purchase' => 50000,
|
|
'max_discount' => 25000,
|
|
'quota' => null,
|
|
'limit_per_user' => null,
|
|
'start_date' => now(),
|
|
'end_date' => null,
|
|
],
|
|
];
|
|
|
|
foreach ($vouchers as $voucher) {
|
|
$newVoucher = Voucher::create($voucher);
|
|
|
|
$newVoucher->outlets()->attach(Outlet::inRandomOrder()->first()->id);
|
|
}
|
|
}
|
|
}
|