8000 [12.x] Add encrypt and decrypt Str helper methods by KIKOmanasijev · Pull Request #55931 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Add encrypt and decrypt Str helper methods #55931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

KIKOmanasijev
Copy link
Contributor
@KIKOmanasijev KIKOmanasijev commented Jun 4, 2025

Inspired from #55767, this PR introduces encrypt() and decrypt() methods to the Illuminate\Support\Stringable class, enabling seamless encryption/decryption within fluent string chains.

Why?

Current approach requires breaking the fluent chain:

$encryptedToken = str('secret-api-token')
    ->pipe(fn(Stringable $str) => encrypt($str->value()))
    ->prepend('encrypted:')
    ->append(':end');

The new methods enable simpler method chaining and provide a more readable alternative:

$encryptedToken = str('secret-api-token')
    ->encrypt()
    ->prepend('encrypted:')
    ->append(':end');

@taylorotwell taylorotwell merged commit 42c39f0 into laravel:12.x Jun 4, 2025
59 checks passed
8000

$this->container->bind('encrypter', fn () => new Encrypter(str_repeat('b', 16)));

$encrypted = encrypt('foo');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually testing the stringable methods that were introduced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this @bretto36, this probably slipped past me.

I opened a new PR #55985 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0