78 lines
3.9 KiB
PHP
78 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Restaurant\Database\Seeders;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Str;
|
|
use Modules\Restaurant\Models\FoodVariant;
|
|
|
|
class FoodVariantTableSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$variants = [
|
|
// Garlic Naan (food_item_id = 1)
|
|
['food_item_id' => 1, 'name' => 'Single Piece', 'price' => 1.99, 'offer_price' => 1.79, 'discount' => 10, 'unit_id' => 1],
|
|
['food_item_id' => 1, 'name' => 'Double Piece', 'price' => 3.49, 'offer_price' => 2.99, 'discount' => 14, 'unit_id' => 1],
|
|
|
|
// Butter Chicken (food_item_id = 2)
|
|
['food_item_id' => 2, 'name' => 'Half Plate', 'price' => 6.99, 'offer_price' => 6.49, 'discount' => 7, 'unit_id' => 1],
|
|
['food_item_id' => 2, 'name' => 'Full Plate', 'price' => 11.99, 'offer_price' => 10.99, 'discount' => 8, 'unit_id' => 1],
|
|
|
|
// Vegetable Biryani (food_item_id = 3)
|
|
['food_item_id' => 3, 'name' => 'Regular', 'price' => 5.49, 'offer_price' => 4.99, 'discount' => 9, 'unit_id' => 1],
|
|
['food_item_id' => 3, 'name' => 'Family Pack', 'price' => 9.99, 'offer_price' => 8.99, 'discount' => 10, 'unit_id' => 1],
|
|
|
|
// Masala Dosa (food_item_id = 4)
|
|
['food_item_id' => 4, 'name' => 'Classic', 'price' => 4.99, 'offer_price' => 4.49, 'discount' => 10, 'unit_id' => 1],
|
|
['food_item_id' => 4, 'name' => 'Cheese Masala Dosa', 'price' => 6.49, 'offer_price' => 5.99, 'discount' => 8, 'unit_id' => 1],
|
|
|
|
// Spring Rolls (food_item_id = 5)
|
|
['food_item_id' => 5, 'name' => '4 pcs', 'price' => 3.99, 'offer_price' => 3.49, 'discount' => 12, 'unit_id' => 1],
|
|
['food_item_id' => 5, 'name' => '8 pcs', 'price' => 6.99, 'offer_price' => 6.49, 'discount' => 7, 'unit_id' => 1],
|
|
|
|
// Paneer Tikka (food_item_id = 6)
|
|
['food_item_id' => 6, 'name' => '6 pcs', 'price' => 5.49, 'offer_price' => 4.99, 'discount' => 9, 'unit_id' => 1],
|
|
['food_item_id' => 6, 'name' => '10 pcs', 'price' => 8.99, 'offer_price' => 7.99, 'discount' => 11, 'unit_id' => 1],
|
|
|
|
// Gulab Jamun (food_item_id = 7)
|
|
['food_item_id' => 7, 'name' => '2 pcs', 'price' => 2.49, 'offer_price' => 2.29, 'discount' => 8, 'unit_id' => 1],
|
|
['food_item_id' => 7, 'name' => '5 pcs', 'price' => 5.49, 'offer_price' => 4.99, 'discount' => 9, 'unit_id' => 1],
|
|
|
|
// Lassi (food_item_id = 8)
|
|
['food_item_id' => 8, 'name' => 'Regular Glass', 'price' => 2.99, 'offer_price' => 2.49, 'discount' => 17, 'unit_id' => 1],
|
|
['food_item_id' => 8, 'name' => 'Large Glass', 'price' => 3.99, 'offer_price' => 3.49, 'discount' => 12, 'unit_id' => 1],
|
|
];
|
|
|
|
$foodItemDefaultMap = []; // Track default per food item
|
|
foreach ($variants as $variant) {
|
|
$foodItemId = $variant['food_item_id'];
|
|
// Assign default only if not assigned before
|
|
$isDefault = isset($foodItemDefaultMap[$foodItemId]) ? false : true;
|
|
if ($isDefault) {
|
|
$foodItemDefaultMap[$foodItemId] = true;
|
|
}
|
|
|
|
FoodVariant::create([
|
|
'restaurant_id' => 1,
|
|
'food_item_id' => $foodItemId,
|
|
'name' => $variant['name'],
|
|
'sku' => 'FV-'.strtoupper(Str::random(8)),
|
|
'price' => $variant['price'],
|
|
'offer_price' => $variant['offer_price'],
|
|
'discount' => $variant['discount'],
|
|
'unit_id' => $variant['unit_id'],
|
|
'description' => $variant['name'].' variant for food ID '.$foodItemId,
|
|
'is_default' => $isDefault,
|
|
'status' => 1,
|
|
'offer_start_at' => Carbon::now(),
|
|
'offer_end_at' => Carbon::now()->addDays(rand(5, 30)),
|
|
]);
|
|
}
|
|
}
|
|
}
|