From d5bd9315b6ca034776d1f6b8b2142af8f41c5c44 Mon Sep 17 00:00:00 2001 From: Tapan Date: Mon, 8 Jan 2024 19:07:42 +0530 Subject: [PATCH] restrict all column to be fetch --- src/Scopes/DecryptSelectScope.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Scopes/DecryptSelectScope.php b/src/Scopes/DecryptSelectScope.php index cd9357b..40f5d00 100644 --- a/src/Scopes/DecryptSelectScope.php +++ b/src/Scopes/DecryptSelectScope.php @@ -18,18 +18,16 @@ class DecryptSelectScope implements Scope */ public function apply(Builder $builder, Model $model) { + $columns = $builder->getQuery()->columns; + $encryptable = $model->encryptable(); $columns = empty($columns) ? Schema::getColumnListing($model->getTable()) : $columns; - if (empty($encryptable) || empty($columns)) { - return $builder->addSelect(...$columns); - } - $select = collect($columns)->map(function ($column) use ($encryptable) { return (in_array($column, $encryptable)) ? db_decrypt($column) : $column; }); - return $builder->addSelect(...$select); + return $builder->select(...$select); } }