8000 [12.x] Add `hash` string helper by istiak-tridip · Pull Request #55767 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Add hash string helper #55767

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

Open
wants to merge 2 commits into
base: 12.x
Choose a base branch
from

Conversation

istiak-tridip
Copy link
Contributor
@istiak-tridip istiak-tridip commented May 17, 2025

This PR adds a new hash method to the Illuminate\Support\Stringable class to simplify fluent string hashing and improve DX.

Why?

Currently, hashing with algorithms like xxh3 (which doesn't have a dedicated hash function) within a fluent chain can be verbose using pipe():

$appId = str('secret-unique-key')
    ->pipe(fn(Stringable $str) => hash('xxh3', (string) $str))
    ->limit(10)
    ->prepend('app-');

This new hash() method provides a more direct and readable alternative:

$appId = str('secret-unique-key')
    ->hash('xxh3')
    ->limit(10)
    ->prepend('app-');

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.

1 participant
0