protected function addWithDecryptKey(Builder $builder)
    {
        $builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
            $model = $builder->getModel();
            $encryptedFields = $model::getEncryptedFields();
            if (!empty($encryptedFields)) {
                $builder->setEncryptionModel($model);

                /** @var DatabaseEncryptionServiceInterface $encryptionService */
                $encryptionService = $model::getEncryptionService();
                foreach ($encryptedFields as $encryptedField) {
                    $decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
                    $builder->addEncryptionSelect([
                        'column' => $encryptedField,
                        'select' => DB::raw("$decryptStmt as $encryptedField")
                    ]);
                }
            }
            return $builder;
        });
    }
protected function addWithDecryptKey(Builder $builder)
    {
        $builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
            $model = $builder->getModel();
            $encryptedFields = $model::getEncryptedFields();
            if (!empty($encryptedFields)) {
                $builder->setEncryptionModel($model);

                /** @var DatabaseEncryptionServiceInterface $encryptionService */
                $encryptionService = $model::getEncryptionService();
                foreach ($encryptedFields as $encryptedField) {
                    $decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
                    $builder->addEncryptionSelect([
                        'column' => $encryptedField,
                        'select' => DB::raw("$decryptStmt as $encryptedField")
                    ]);
                }
            }
            return $builder;
        });
    }
protected function addWithDecryptKey ( Builder $ builder ) { $ builder -> macro ( 'withDecryptKey' , function ( Builder $ builder , $ decryptKey ) { $ model = $ builder -> getModel ( ) ; $ encryptedFields = $ model :: getEncryptedFields ( ) ; if ( ! empty ( $ encryptedFields ) ) { $ builder -> setEncryptionModel ( $ model ) ; /** @var DatabaseEncryptionServiceInterface $encryptionService */ $ encryptionService = $ model :: getEncryptionService ( ) ; foreach ( $ encryptedFields as $ encryptedField ) { $ decryptStmt = $ encryptionService -> getDecryptExpression ( $ encryptedField , $ decryptKey ) ; $ builder -> addEncryptionSelect ( [ 'column' => $ encryptedField , 'select' => DB :: raw ( "$decryptStmt as $encryptedField" ) ] ) ; } } return $ builder ; } ) ; }
Add the with-decrypt-key extension to the builder.

@param  \Illuminate\Database\Eloquent\Builder $builder
@return void
Add the with - decrypt - key extension to the builder .