is_string($year) ? trim($year) : null, $schoolYears )))); if ($years === []) { return; } $statuses = SchoolYear::query() ->whereIn('name', $years) ->get(['name', 'status']) ->keyBy('name'); foreach ($years as $year) { $row = $statuses->get($year); if ($row && in_array($row->status, [SchoolYear::STATUS_CLOSED, SchoolYear::STATUS_ARCHIVED], true)) { throw new RuntimeException(sprintf( 'School year %s is %s and read-only.', $year, $row->status )); } } } }