You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.4 KiB

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Appointment;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Illuminate\Support\Facades\DB;
class AppointmentTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$latestAppointment = DB::table('appointments')->latest('date')->first();
$startDate = $latestAppointment ? Carbon::parse($latestAppointment->date)->addDay() : Carbon::now();
$startTime = Carbon::parse("9:00 AM");
$endTime = Carbon::parse("5:00 PM");
foreach(config('custom.service_type') as $key => $value){
for ($i = 0; $i < 7; $i++) {
$date = $startDate->copy()->addDays($i);
for ($j = 0; $j <= ((($endTime->diffInMinutes($startTime)) / 30)-1); $j++) {
$currentTime = $startTime->copy()->addMinutes(30 * $j);
$currentEndTime = $startTime->copy()->addMinutes(30 * $j + 30);
DB::table('appointments')->insert([
'date' => $date,
'start_time' => $currentTime->format("H:i A"),
'end_time' => $currentEndTime->format("H:i A"),
'service_type' => $key
]);
}
}
}
}
}