Skip to content

Commit daa0516

Browse files
[12.x] Add hash method to strings (#10471)
* Add hash method to strings * wip * Update strings.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent be2562c commit daa0516

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

strings.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Laravel includes a variety of functions for manipulating string values. Many of
152152
[excerpt](#method-fluent-str-excerpt)
153153
[explode](#method-fluent-str-explode)
154154
[finish](#method-fluent-str-finish)
155+
[hash](#method-fluent-str-hash)
155156
[headline](#method-fluent-str-headline)
156157
[inlineMarkdown](#method-fluent-str-inline-markdown)
157158
[is](#method-fluent-str-is)
@@ -2278,6 +2279,19 @@ $adjusted = Str::of('this/string/')->finish('/');
22782279
// this/string/
22792280
```
22802281

2282+
<a name="method-fluent-str-hash"></a>
2283+
#### `hash` {.collection-method}
2284+
2285+
The `hash` method hashes the string using the given [algorithm](https://www.php.net/manual/en/function.hash-algos.php):
2286+
2287+
```php
2288+
use Illuminate\Support\Str;
2289+
2290+
$hashed = Str::of('secret')->hash(algorithm: 'sha256');
2291+
2292+
// '2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b'
2293+
```
2294+
22812295
<a name="method-fluent-str-headline"></a>
22822296
#### `headline` {.collection-method}
22832297

0 commit comments

Comments
 (0)