Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

$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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.