diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 5a573803868b..4b88790ecf38 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -529,6 +529,28 @@ public function trim($characters = null) return new static(trim(...array_merge([$this->value], func_get_args()))); } + /** + * Left trim the string of the given characters. + * + * @param string $characters + * @return static + */ + public function ltrim($characters = null) + { + return new static(ltrim(...array_merge([$this->value], func_get_args()))); + } + + /** + * Right trim the string of the given characters. + * + * @param string $characters + * @return static + */ + public function rtrim($characters = null) + { + return new static(rtrim(...array_merge([$this->value], func_get_args()))); + } + /** * Make a string's first character uppercase. * diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 363ff565ba2f..5844c97e70f8 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -51,6 +51,16 @@ public function testTrim() $this->assertSame('foo', (string) $this->stringable(' foo ')->trim()); } + public function testLtrim() + { + $this->assertSame('foo ', (string) $this->stringable(' foo ')->ltrim()); + } + + public function testRtrim() + { + $this->assertSame(' foo', (string) $this->stringable(' foo ')->rtrim()); + } + public function testCanBeLimitedByWords() { $this->assertSame('Taylor...', (string) $this->stringable('Taylor Otwell')->words(1));