Skip to content

Commit

Permalink
issue fixed for duplicating selecting fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhara committed Jan 10, 2024
1 parent b272e4d commit c223c1b
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Scopes/DecryptSelectScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,16 @@ class DecryptSelectScope implements Scope
*/
public function apply(Builder $builder, Model $model)
{
$columns = [];
$query = $builder->getQuery();

if (isset($query)) {
$columns = $query->columns;
}
$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);
}
}

0 comments on commit c223c1b

Please sign in to comment.