ArrayObject.php
1 month ago
AsArrayObject.php
1 month ago
AsCollection.php
1 month ago
AsEncryptedArrayObject.php
1 month ago
AsEncryptedCollection.php
1 month ago
AsEnumArrayObject.php
1 month ago
AsEnumCollection.php
1 month ago
AsStringable.php
1 month ago
Attribute.php
1 month ago
AsStringable.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Eloquent\Casts; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Contracts\Database\Eloquent\Castable; |
| 6 | use IAWPSCOPED\Illuminate\Contracts\Database\Eloquent\CastsAttributes; |
| 7 | use IAWPSCOPED\Illuminate\Support\Str; |
| 8 | /** @internal */ |
| 9 | class AsStringable implements Castable |
| 10 | { |
| 11 | /** |
| 12 | * Get the caster class to use when casting from / to this cast target. |
| 13 | * |
| 14 | * @param array $arguments |
| 15 | * @return CastsAttributes<\Illuminate\Support\Stringable, string|\Stringable> |
| 16 | */ |
| 17 | public static function castUsing(array $arguments) |
| 18 | { |
| 19 | return new class implements CastsAttributes |
| 20 | { |
| 21 | public function get($model, $key, $value, $attributes) |
| 22 | { |
| 23 | return isset($value) ? Str::of($value) : null; |
| 24 | } |
| 25 | public function set($model, $key, $value, $attributes) |
| 26 | { |
| 27 | return isset($value) ? (string) $value : null; |
| 28 | } |
| 29 | }; |
| 30 | } |
| 31 | } |
| 32 |