From 64636df8a0558aed5e5376570212d6892b3e793b Mon Sep 17 00:00:00 2001 From: Hammed Oyedele Date: Wed, 22 Jul 2026 13:26:17 +0100 Subject: [PATCH 1/2] feat: add plainString method to retrieve data as a string --- .../Support/Traits/InteractsWithData.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Illuminate/Support/Traits/InteractsWithData.php b/src/Illuminate/Support/Traits/InteractsWithData.php index bef9de2e5ccc..af9953a816cb 100644 --- a/src/Illuminate/Support/Traits/InteractsWithData.php +++ b/src/Illuminate/Support/Traits/InteractsWithData.php @@ -264,6 +264,22 @@ public function string($key, $default = null) return new Stringable($this->data($key, $default)); } + /** + * Retrieve data from the instance as a string. + * + * @param string $key + * @param mixed $default + * @return string + */ + public function plainString($key, $default = null) + { + if ($this->isNotFilled($key)) { + return value($default); + } + + return (string) $this->data($key); + } + /** * Retrieve data as a boolean value. * From 2e60e283ec37962e0f72751aee528ed3f11fbd09 Mon Sep 17 00:00:00 2001 From: Hammed Oyedele Date: Wed, 22 Jul 2026 13:37:17 +0100 Subject: [PATCH 2/2] fix: update plainString return type and add tests for edge cases --- .../Support/Traits/InteractsWithData.php | 2 +- tests/Http/HttpRequestTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Traits/InteractsWithData.php b/src/Illuminate/Support/Traits/InteractsWithData.php index af9953a816cb..0855a8ea45e2 100644 --- a/src/Illuminate/Support/Traits/InteractsWithData.php +++ b/src/Illuminate/Support/Traits/InteractsWithData.php @@ -269,7 +269,7 @@ public function string($key, $default = null) * * @param string $key * @param mixed $default - * @return string + * @return string|null */ public function plainString($key, $default = null) { diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index 078bc04612fc..885e732814c2 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -683,6 +683,31 @@ public function testStringMethod() $this->assertSame('', $request->string('unknown_key')->value()); } + public function testPlainStringMethod() + { + $request = Request::create('/', 'GET', [ + 'int' => 123, + 'int_str' => '456', + 'float' => 123.456, + 'float_str' => '123.456', + 'float_zero' => 0.000, + 'float_str_zero' => '0.000', + 'str' => 'abc', + 'empty_str' => '', + 'null' => null, + ]); + $this->assertSame('123', $request->plainString('int')); + $this->assertSame('456', $request->plainString('int_str')); + $this->assertSame('123.456', $request->plainString('float')); + $this->assertSame('123.456', $request->plainString('float_str')); + $this->assertSame('0', $request->plainString('float_zero')); + $this->assertSame('0.000', $request->plainString('float_str_zero')); + $this->assertSame(null, $request->plainString('empty_str')); + $this->assertSame(null, $request->plainString('null')); + $this->assertSame(null, $request->plainString('unknown_key')); + $this->assertSame('default', $request->plainString('unknown_key', 'default')); + } + public function testBooleanMethod() { $request = Request::create('/', 'GET', ['with_trashed' => 'false', 'download' => true, 'checked' => 1, 'unchecked' => '0', 'with_on' => 'on', 'with_yes' => 'yes']);