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.

50 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()
{
2 years ago
$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");
2 years ago
foreach(config('custom.service_type') as $key => $value){
2 years ago
for ($i = 0; $i < 7; $i++) {
2 years ago
$date = $startDate->copy()->addDays($i);
for ($j = 0; $j <= ((($endTime->diffInMinutes($startTime)) / 30)-1); $j++) {
2 years ago
$currentTime = $startTime->copy()->addMinutes(30 * $j);
$currentEndTime = $startTime->copy()->addMinutes(30 * $j + 30);
2 years ago
DB::table('appointments')->insert([
'date' => $date,
'start_time' => $currentTime->format("H:i A"),
'end_time' => $currentEndTime->format("H:i A"),
'service_type' => $key
]);
}
}
}
2 years ago
}
}