Skip to content

Commit

Permalink
restrict all column to be fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapan-Tops committed Jan 8, 2024
1 parent a2f6704 commit d5bd931
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Scopes/DecryptSelectScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d5bd931

Please sign in to comment.