Skip to content

[9.x] Add methods to cast Stringables - #44238

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
jasonmccreary:stringable-casting
Sep 21, 2022
Merged

[9.x] Add methods to cast Stringables#44238
taylorotwell merged 1 commit into
laravel:9.xfrom
jasonmccreary:stringable-casting

Conversation

@jasonmccreary

@jasonmccreary jasonmccreary commented Sep 21, 2022

Copy link
Copy Markdown
Contributor

This adds methods to conveniently cast stringables to common data types similar to those found in Laravel's HTTP Request.

Before

intval(str('shift-worker-01')->afterLast('-')->toString());
floatval(str('Result: 1.23')->after(':')->trim()->toString());
str('YeS')->lower()->toString() === 'yes';
Carbon::parse(str('DOB: 12-31-2001')->after(':')->trim()->toString());

After

str('shift-worker-01')->afterLast('-')->toInteger();
str('Result: 1.23')->after(':')->trim()->toFloat();
str('YeS')->lower()->toBoolean();
str('DOB: 12-31-2001')->after(':')->trim()->toDate();

@taylorotwell
taylorotwell merged commit 66d3757 into laravel:9.x Sep 21, 2022
@jasonmccreary
jasonmccreary deleted the stringable-casting branch September 21, 2022 22:34
@GrahamCampbell GrahamCampbell changed the title Add methods to cast Stringables [9.x] Add methods to cast Stringables Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants