From 2ce3dfffb66d3fda51e3fdeb4b96868d37ef0c17 Mon Sep 17 00:00:00 2001 From: Charlie Waddell Date: Wed, 30 Jun 2021 19:50:16 +0100 Subject: [PATCH] Adding exists to Buildable --- src/Traits/Buildable.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Traits/Buildable.php b/src/Traits/Buildable.php index 79e291a8..ce14af5b 100644 --- a/src/Traits/Buildable.php +++ b/src/Traits/Buildable.php @@ -29,6 +29,17 @@ public function count($columns = "*") return $this->cachedValue(func_get_args(), $cacheKey); } + public function exists() + { + if (! $this->isCachable()) { + return parent::exists(); + } + + $cacheKey = $this->makeCacheKey(['*'], null, "-exists"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + public function decrement($column, $amount = 1, array $extra = []) { $this->cache($this->makeCacheTags()) @@ -117,7 +128,7 @@ public function insert(array $values) if (property_exists($this, "model")) { $this->checkCooldownAndFlushAfterPersisting($this->model); } - + return parent::insert($values); }