diff --git a/Collection.php b/Collection.php index 3b3725e..1764c8f 100644 --- a/Collection.php +++ b/Collection.php @@ -50,6 +50,27 @@ class Collection extends AbstractCollection return $_tmp; } + + /** + * @param array $attributes + * @return bool + * @throws Exception + */ + public function update(array $attributes): bool + { + $lists = []; + $primary = $this->getModel()->getPrimary(); + $items = $this->getItems(); + if ($this->isEmpty() || !isset($items[0][$primary])) { + return false; + } + foreach ($items as $item) { + $lists[] = $item[$primary]; + } + return $this->getModel()::query()->whereIn($primary, $lists) + ->batchUpdate($attributes); + } + /** * @param string $field * @return array|null diff --git a/Mysql/Columns.php b/Mysql/Columns.php index 17162df..d600fd4 100644 --- a/Mysql/Columns.php +++ b/Mysql/Columns.php @@ -187,7 +187,7 @@ class Columns extends Component */ #[Pure] public function isJson($format): bool { - return in_array($format, ['json']); + return $format == 'json'; } /**