Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Sep 21, 2022

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