Files

72 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2026-03-15 17:08:23 +07:00
<?php
namespace Modules\Restaurant\Database\Seeders;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ReservationSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Sample restaurant and table IDs
$restaurantIds = [1];
$tableIds = [1, 2, 3, 4, 5];
$customerIds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
// Clear old data
DB::table('reservations')->truncate();
DB::table('reservation_unavailables')->truncate();
// Seed reservations
foreach (range(1, 10) as $i) {
$restaurantId = $restaurantIds[array_rand($restaurantIds)];
$tableId = $tableIds[array_rand($tableIds)];
$customerId = $customerIds[array_rand($customerIds)];
$date = Carbon::now()->addDays(rand(0, 5))->toDateString();
$startTime = Carbon::createFromTime(rand(10, 20), [0, 30][rand(0, 1)]);
$endTime = (clone $startTime)->addHours(2);
DB::table('reservations')->insert([
'restaurant_id' => $restaurantId,
'table_id' => $tableId,
'customer_id' => $customerId,
'reservation_date' => $date,
'start_time' => $startTime->format('H:i:s'),
'end_time' => $endTime->format('H:i:s'),
'people_count' => rand(2, 8),
'status' => collect(['booked', 'free', 'upcoming', 'cancelled'])->random(),
'note' => fake()->sentence(),
'created_at' => now(),
'updated_at' => now(),
]);
}
// Seed unavailable times
foreach (range(1, 5) as $i) {
$restaurantId = $restaurantIds[array_rand($restaurantIds)];
$tableId = $tableIds[array_rand($tableIds)];
$date = Carbon::now()->addDays(rand(0, 5))->toDateString();
$startTime = Carbon::createFromTime(rand(10, 22), [0, 30][rand(0, 1)]);
$endTime = (clone $startTime)->addHours(rand(1, 3));
DB::table('reservation_unavailables')->insert([
'restaurant_id' => $restaurantId,
'table_id' => $tableId,
'date' => $date,
'start_time' => $startTime->format('H:i:s'),
'end_time' => $endTime->format('H:i:s'),
'reason' => fake()->sentence(),
'created_at' => now(),
'updated_at' => now(),
]);
}
}
}