26 lines
790 B
PHP
26 lines
790 B
PHP
<?php
|
|
|
|
namespace DishPlanner\Schedule\Actions;
|
|
|
|
use App\Models\Planner;
|
|
use App\Models\Schedule;
|
|
use App\Models\ScheduledUserDish;
|
|
use Carbon\Carbon;
|
|
|
|
class ClearScheduleForMonthAction
|
|
{
|
|
public function execute(Planner $planner, int $month, int $year, array $userIds): void
|
|
{
|
|
$startDate = Carbon::createFromDate($year, $month, 1)->startOfDay();
|
|
$endDate = $startDate->copy()->endOfMonth()->endOfDay();
|
|
|
|
$scheduleIds = Schedule::withoutGlobalScopes()
|
|
->where('planner_id', $planner->id)
|
|
->whereBetween('date', [$startDate->format('Y-m-d'), $endDate->format('Y-m-d')])
|
|
->pluck('id');
|
|
|
|
ScheduledUserDish::whereIn('schedule_id', $scheduleIds)
|
|
->whereIn('user_id', $userIds)
|
|
->delete();
|
|
}
|
|
}
|