Skip to content

Commit f7bd7ef

Browse files
[2.x] Add Stringable caster (#121)
* Add Stringable caster * Update TinkerCaster.php Co-authored-by: Dries Vints <[email protected]>
1 parent 383bf7f commit f7bd7ef

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Console/TinkerCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected function getCasters()
118118
$casters = [
119119
'Illuminate\Support\Collection' => 'Laravel\Tinker\TinkerCaster::castCollection',
120120
'Illuminate\Support\HtmlString' => 'Laravel\Tinker\TinkerCaster::castHtmlString',
121+
'Illuminate\Support\Stringable' => 'Laravel\Tinker\TinkerCaster::castStringable',
121122
];
122123

123124
if (class_exists('Illuminate\Database\Eloquent\Model')) {

src/TinkerCaster.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ public static function castHtmlString($htmlString)
8181
];
8282
}
8383

84+
/**
85+
* Get an array representing the properties of a fluent string.
86+
*
87+
* @param \Illuminate\Support\Stringable $stringable
88+
* @return array
89+
*/
90+
public static function castStringable($stringable)
91+
{
92+
return [
93+
Caster::PREFIX_VIRTUAL.'value' => (string) $stringable,
94+
];
95+
}
96+
8497
/**
8598
* Get an array representing the properties of a model.
8699
*

0 commit comments

Comments
 (0)