From c7ad5123e21266d23f15fc0b182d57af88600a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 7 Sep 2022 14:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Collection.php | 21 +++++++++++++++++++++ Mysql/Columns.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) 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'; } /**