diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 7d3558c0fdc9..018416d9ac73 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -797,6 +797,18 @@ public function title() return new static(Str::title($this->value)); } + /** + * Transliterate a string to its closest ASCII representation. + * + * @param string|null $unknown + * @param bool|null $strict + * @return static + */ + public function transliterate($unknown = '?', $strict = false) + { + return new static(Str::transliterate($this->value, $unknown, $strict)); + } + /** * Convert the given string to title case for each word. * diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 39506394a044..5cf433fa4973 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -527,6 +527,12 @@ public function testAscii() $this->assertSame('u', (string) $this->stringable('ΓΌ')->ascii()); } + public function testTransliterate() + { + $this->assertSame('HHH', (string) $this->stringable('πŸŽ‚πŸš§πŸ†')->transliterate('H')); + $this->assertSame('Hello', (string) $this->stringable('πŸŽ‚')->transliterate('Hello')); + } + public function testNewLine() { $this->assertSame('Laravel'.PHP_EOL, (string) $this->stringable('Laravel')->newLine());