Migrating from PHP

laravel-rust-format Alpha Laravel for Rust

Used in production across multiple projects.

Use this lookup with use laravel_rust_format_core::{php, str, number, carbon};. With the adapter, the same modules are available from laravel_rust_format. MiniJinja entries are template expressions. A dash means you can format in Rust and pass the result in the view context.

Use Rust semantics for new code. Use explicit php:: calls where a migrated template depends on PHP’s output or coercions. PHP variable names become Rust or template variable names in these examples. The table assumes Precision is imported from number and Relative from carbon. For localized number entries, locale is a Rust locale context or a MiniJinja locale code, respectively.

PHP or Blade callRustMiniJinja
Str::of($s)->trim()->slug()->toString()str::of(s).trim().slug().into_string()—
Str::of($s)->toBoolean()str::of(s).to_boolean()s|str_to_boolean
Str::of($s)->scan($format)str::of(s).scan(format)? or str::scan(s, format)?s|str_scan(format)
Str::of($s)->split($pattern, $limit, $flags)str::of(s).split_with(pattern, str::SplitOptions::new(limit, flags))?s|str_split(pattern, limit, flags)
Str::of($s)->split($length)str::of(s).split_chars(length)?—
preg_split($pattern, $s, $limit, $flags)php::preg_split_with(pattern, s, str::SplitOptions::new(limit, flags))?s|str_split(pattern, limit, flags) for UTF-8 output
number_format($n)php::number_format(n, 0)n|number_format
number_format($n, $digits, $point, $sep)php::number_format_with(n, digits, point, sep)n|number_format(digits, point, sep)
round($n, $digits)php::round(n, digits)n|php_round(digits)
round($n, $digits, RoundingMode::HalfEven)php::round_with(n, digits, php::RoundingMode::HalfEven)n|php_round(digits, mode="HalfEven")
echo $n / {{ $n }} for a numberphp::echo(n)n|php_echo
echo $valuephp::echo(&value)—
(bool) $value / boolval($value)php::boolval(&value)—
$a == $b with PHP coercionphp::loose_eq(&a, &b)—
(int) $value / intval($value)php::intval(&value)—
(float) $value / floatval($value)php::floatval(&value)—
(string) $value / strval($value)php::strval(&value)—
sprintf($format, ...$args)php::sprintf(format, &args)?—
printf($format, ...$args)php::printf(&mut sink, format, &args)?—
vprintf($format, $values)php::vprintf(&mut sink, format, &values)?—
fprintf($stream, $format, ...$args)php::fprintf(&mut stream, format, &args)?—
array_filter($array)php::array_filter(&array)? (keeps original keys)—
array_values($array)php::array_values(&array)? (starts keys again at zero)—
json_encode($value)php::json_encode(&value, php::JsonFlags::NONE)?value|php_json_encode
json_encode($value, $flags, $depth)php::json_encode_with(&value, flags, depth)?value|php_json_encode(flags, depth)
json_encode($bytes, $flags) for a PHP byte stringphp::json_encode_bytes(bytes, flags)?—
Js::from($value, $flags, $depth) or Blade’s @js directivejs::from(&value, flags, depth)?value|js_from(flags, depth)
Blade @json($value)php::json_encode(&value, php::JsonFlags::BLADE)?value|blade_json
ucfirst($s)php::ucfirst(s)s|ucfirst
lcfirst($s)php::lcfirst(s)s|php_lcfirst
ucwords($s)php::ucwords(s)s|php_ucwords
ucwords($s, $separators)php::ucwords_with(s, separators)s|php_ucwords(separators)
strtolower($s)php::strtolower(s)s|php_strtolower
strtoupper($s)php::strtoupper(s)s|php_strtoupper
Numeric string conversion after is_numeric($s)PhpNumber::from_numeric_str(s)Numeric filters parse numeric strings directly
nl2br($s, $is_xhtml)php::nl2br_with(s, is_xhtml) or php::nl2br(s)s|php_nl2br(is_xhtml)
str_pad($s, $n, $pad, $side)php::str_pad_with(s, n, pad, side) or php::str_pad(s, n)s|php_str_pad(n, pad, side)
mb_str_pad($s, $n, $pad, $side, 'UTF-8')php::mb_str_pad_with(s, n, pad, side) or php::mb_str_pad(s, n)—
wordwrap($s, $width, $break, $cut)php::wordwrap_with(s, width, line_break, cut) or php::wordwrap(s)s|php_wordwrap(width, line_break, cut)
htmlspecialchars($s, $flags, 'UTF-8', $double)php::htmlspecialchars_with(s, flags, double) or php::htmlspecialchars(s)—
htmlspecialchars_decode($s, $flags)php::htmlspecialchars_decode_with(s, flags) or php::htmlspecialchars_decode(s)—
html_entity_decode($s, $flags, 'UTF-8')php::html_entity_decode_with(s, flags) or php::html_entity_decode(s)—
htmlentities($s, $flags, 'UTF-8', $double)php::htmlentities_with(s, flags, double) or php::htmlentities(s)—
e($value, $double), Blade {{ $value }} for scalar valuesphp::e_with(&value, double) or php::e(&value)—
strip_tags($s, $allowed)php::strip_tags(s, &allowed), with PhpValue::Null for the defaults|php_strip_tags(allowed)
trim($s, $mask)php::trim_with(s, mask) or php::trim(s)—
ltrim($s, $mask)php::ltrim_with(s, mask) or php::ltrim(s)—
rtrim($s, $mask)php::rtrim_with(s, mask) or php::rtrim(s)—
str_repeat($s, $times)php::str_repeat(s, times)—
strrev($s)php::strrev(s)—
substr($s, $offset, $length)php::substr(s, offset, length), with None to take the tail—
strlen($value)php::strlen(&value)—
mb_substr($s, $start, $length, 'UTF-8')php::mb_substr(s, start, length), with None to take the tail—
mb_strlen($s, 'UTF-8')php::mb_strlen(s)—
mb_strwidth($s, 'UTF-8')php::mb_strwidth(s)—
mb_strimwidth($s, $start, $width, $marker, 'UTF-8')php::mb_strimwidth(s, start, width, marker)—
mb_str_split($s, $length, 'UTF-8')php::mb_str_split(s, length)—
str_word_count($s, 0, $characters)php::str_word_count(s, characters), with None for the default mask—
strtr($s, $pairs)php::strtr(s, &pairs)—
str_replace($search, $replace, $subject, $count)php::str_replace(&search, &replace, &subject)—
str_ireplace($search, $replace, $subject, $count)php::str_ireplace(&search, &replace, &subject)—
addslashes($s)php::addslashes(s)—
stripslashes($s)php::stripslashes(s)—
quotemeta($s)php::quotemeta(s)—
urlencode($s)php::urlencode(s)—
rawurlencode($s)php::rawurlencode(s)—
urldecode($s)php::urldecode(s)—
rawurldecode($s)php::rawurldecode(s)—
http_build_query($data, $prefix, $separator, $mode)php::http_build_query_with(&data, prefix, separator, mode) or php::http_build_query(&data)—
base64_encode($s)php::base64_encode(s), also accepts raw bytes—
base64_decode($s, $strict)php::base64_decode_with(s, strict) or php::base64_decode(s)—
bin2hex($s)php::bin2hex(s), also accepts raw bytes—
crc32($s)php::crc32(s), also accepts raw bytes—
implode($separator, $parts)php::implode(separator, &parts), with "" for PHP's implicit separator—
Arr::join($parts, $glue)arr::join(&parts, glue)?parts|arr_join(glue)
Arr::join($parts, $glue, $finalGlue)arr::join_with(&parts, glue, final_glue)?parts|arr_join(glue, final_glue)
$collection->join($glue, $finalGlue)arr::collection_join_with(&items, glue, final_glue)?—
explode($separator, $s, $limit)php::explode(separator, s, limit), with i64::MAX for PHP's default limit—
Str::limit($s, $n)str::limit(s, n)s|str_limit(n)
Str::limit($s, $n, $end)str::limit_with(s, n, end)s|str_limit(n, end)
Str::limit($s, $n, $end, preserveWords: true)str::Limit::new(n).end(end).preserve_words().apply(s)s|str_limit(n, end, preserve_words=true)
Str::words($s, $n)str::words(s, n)s|str_words(n)
Str::words($s, $n, $end)str::words_with(s, n, end)s|str_words(n, end)
Str::title($s)str::title(s)s|str_title
Str::headline($s)str::headline(s)s|str_headline
Str::ucfirst($s)str::ucfirst(s)s|str_ucfirst
Str::lcfirst($s)str::lcfirst(s)s|str_lcfirst
Str::upper($s)str::upper(s)s|str_upper
Str::lower($s)str::lower(s)s|str_lower
Str::ucsplit($s)str::ucsplit(s)—
Str::ascii($s)str::ascii(s)s|str_ascii
Str::ascii($s, $language)str::ascii_with(s, language)s|str_ascii(language)
Str::slug($s)str::slug(s)s|str_slug
Str::slug($s, $sep)str::slug_with(s, sep)s|str_slug(sep)
Str::slug($s, $sep, $language)str::Slug::new().separator(sep).language(language).apply(s)s|str_slug(sep, language)
Str::slug($s, $sep, $language, $dict)Add .dictionary(dict) before .apply(s), passing pairs in PHP order—
Str::plural($s)str::pluralize(s)s|str_plural
Str::plural($s, $count)str::plural(s, count)s|str_plural(count) or plural(s, count)
Str::plural($s, $count, prependCount: true)str::plural_with_count(s, count)s|str_plural(count, prepend_count=true)
Str::singular($s)str::singular(s)s|str_singular
Str::pluralStudly($s, $count)str::plural_studly(s, count)—
Str::pluralPascal($s, $count)str::plural_pascal(s, count)—
Str::after($s, $n)str::after(s, n)s|str_after(n)
Str::afterLast($s, $n)str::after_last(s, n)s|str_after_last(n)
Str::before($s, $n)str::before(s, n)s|str_before(n)
Str::beforeLast($s, $n)str::before_last(s, n)s|str_before_last(n)
Str::between($s, $from, $to)str::between(s, from, to)s|str_between(from, to)
Str::betweenFirst($s, $from, $to)str::between_first(s, from, to)s|str_between_first(from, to)
Str::charAt($s, $index)str::char_at(s, index)—
Str::chopStart($s, $prefix)str::chop_start(s, prefix)—
Str::chopStart($s, $prefixes)str::chop_start_any(s, prefixes)—
Str::chopEnd($s, $suffix)str::chop_end(s, suffix)—
Str::chopEnd($s, $suffixes)str::chop_end_any(s, suffixes)—
Str::contains($s, $n)str::contains(s, n)—
Str::contains($s, $n, $ignoreCase)str::contains_with(s, n, ignore_case)—
Str::contains($s, $needles)str::contains_any(s, needles)—
Str::contains($s, $needles, $ignoreCase)str::contains_any_with(s, needles, ignore_case)—
Str::containsAll($s, $needles)str::contains_all(s, needles)—
Str::containsAll($s, $needles, $ignoreCase)str::contains_all_with(s, needles, ignore_case)—
Str::doesntContain($s, $n)str::doesnt_contain(s, n)—
Str::doesntContain($s, $n, $ignoreCase)str::doesnt_contain_with(s, n, ignore_case)—
Str::doesntContain($s, $needles)str::doesnt_contain_any(s, needles)—
Str::doesntContain($s, $needles, $ignoreCase)str::doesnt_contain_any_with(s, needles, ignore_case)—
Str::startsWith($s, $prefix)str::starts_with(s, prefix)—
Str::startsWith($s, $prefixes)str::starts_with_any(s, prefixes)—
Str::doesntStartWith($s, $prefix)str::doesnt_start_with(s, prefix)—
Str::doesntStartWith($s, $prefixes)str::doesnt_start_with_any(s, prefixes)—
Str::endsWith($s, $suffix)str::ends_with(s, suffix)—
Str::endsWith($s, $suffixes)str::ends_with_any(s, suffixes)—
Str::doesntEndWith($s, $suffix)str::doesnt_end_with(s, suffix)—
Str::doesntEndWith($s, $suffixes)str::doesnt_end_with_any(s, suffixes)—
Str::position($s, $n)str::position(s, n)—
Str::position($s, $n, $offset, $encoding)str::position_with(s, n, offset, encoding)—
Str::substr($s, $start)str::substr(s, start)—
Str::substr($s, $start, $length)str::substr_with(s, start, length)—
Str::substr($s, $start, $length, $encoding)str::substr_encoded(s, start, length, encoding)—
Str::substrCount($s, $n)str::substr_count(s, n)—
Str::substrCount($s, $n, $offset, $length)str::substr_count_with(s, n, offset, length)—
Str::substrReplace($s, $replacement)str::substr_replace(s, replacement)—
Str::substrReplace($s, $replacement, $offset, $length) with strings and scalar offsetsstr::substr_replace_with(s, replacement, offset, length)—
Str::substrReplace($s, $replacement, $offset, $length) with array argumentsstr::substr_replace_values(&s, &replacement, &offset, &length) using PhpValue—
Str::take($s, $limit)str::take(s, limit)—
Str::length($s)str::length(s)—
Str::length($s, $encoding)str::length_with(s, encoding)—
Str::excerpt($s, $phrase)str::excerpt(s, phrase)—
Str::excerpt($s, $phrase, ['radius' => $r, 'omission' => $o])str::excerpt_with(s, phrase, r, o)—
Str::finish($s, $cap)str::finish(s, cap)—
Str::start($s, $prefix)str::start(s, prefix)—
Str::wrap($s, $border)str::wrap(s, border)—
Str::wrap($s, $before, $after)str::wrap_with(s, before, after)—
Str::unwrap($s, $border)str::unwrap(s, border)—
Str::unwrap($s, $before, $after)str::unwrap_with(s, before, after)—
Str::is($pattern, $s)str::is(pattern, s)—
Str::is($pattern, $s, $ignoreCase)str::is_with(pattern, s, ignore_case)—
Str::is($patterns, $s)str::is_any(patterns, s)—
Str::is($patterns, $s, $ignoreCase)str::is_any_with(patterns, s, ignore_case)—
Str::isAscii($s)str::is_ascii(s)—
Str::isJson($s)str::is_json(s)—
Str::isUrl($s)str::is_url(s)—
Str::isUrl($s, $protocols)str::is_url_with(s, protocols)—
Str::isUuid($s)str::is_uuid(s)—
Str::isUuid($s, $version)str::is_uuid_with(s, version) using UuidVersion::Number(n), UuidVersion::Nil, or UuidVersion::Max—
Str::isUlid($s)str::is_ulid(s)—
Str::counted($word, $count)str::counted(word, count)—
Str::parseCallback($callback)str::parse_callback(callback)—
Str::parseCallback($callback, $default)str::parse_callback_with(callback, Some(default))—
Str::camel($s)str::camel(s)s|str_camel
Str::kebab($s)str::kebab(s)s|str_kebab
Str::snake($s, $delimiter)str::snake(s) or str::snake_with(s, delimiter)s|str_snake(delimiter)
Str::studly($s, $normalize)str::studly(s) or str::studly_with(s, normalize)s|str_studly(normalize)
Str::pascal($s, $normalize)str::pascal(s) or str::pascal_with(s, normalize)—
Str::convertCase($s, $mode)str::convert_case(s) or str::convert_case_with(s, mode)—
Str::deduplicate($s, $characters)str::deduplicate(s) or str::deduplicate_with(s, characters)—
Str::mask($s, $char, $index, $length)str::mask(s, ch, index) or str::mask_with(s, ch, index, length)s|str_mask(character, index, length)
Str::numbers($s)str::numbers(s)—
Str::padBoth($s, $length, $pad)str::pad_both(s, length) or str::pad_both_with(s, length, pad)s|str_pad_both(length, pad)
Str::padLeft($s, $length, $pad)str::pad_left(s, length) or str::pad_left_with(s, length, pad)s|str_pad_left(length, pad)
Str::padRight($s, $length, $pad)str::pad_right(s, length) or str::pad_right_with(s, length, pad)s|str_pad_right(length, pad)
Str::repeat($s, $times)str::repeat(s, times)—
Str::replace($search, $replace, $s, $caseSensitive)str::replace(search, replacement, s), str::replace_with(search, replacement, s, case_sensitive) or str::replace_many(searches, replacements, s, case_sensitive)s|str_replace(search, replacement, case_sensitive)
Str::replaceArray($search, $replace, $s)str::replace_array(search, replacements, s)—
Str::replaceFirst($search, $replace, $s)str::replace_first(search, replacement, s)—
Str::replaceLast($search, $replace, $s)str::replace_last(search, replacement, s)—
Str::replaceStart($search, $replace, $s)str::replace_start(search, replacement, s)—
Str::replaceEnd($search, $replace, $s)str::replace_end(search, replacement, s)—
Str::remove($search, $s, $caseSensitive)str::remove(search, s) or str::remove_with(searches, s, case_sensitive)—
Str::reverse($s)str::reverse(s)—
Str::swap($map, $s)str::swap(pairs, s)—
Str::squish($s)str::squish(s)s|str_squish
Str::trim($s, $charlist)str::trim(s) or str::trim_with(s.as_bytes(), charlist)—
Str::ltrim($s, $charlist)str::ltrim(s) or str::ltrim_with(s.as_bytes(), charlist)—
Str::rtrim($s, $charlist)str::rtrim(s) or str::rtrim_with(s.as_bytes(), charlist)—
Str::ucwords($s, $separators)str::ucwords(s) or str::ucwords_with(s, separators)—
Str::wordCount($s, $characters)str::word_count(s) or str::word_count_with(s, characters)—
Str::wordWrap($s, $width, $break, $cut)str::word_wrap(s) or str::word_wrap_with(s, width, line_break, cut)s|str_word_wrap(width, line_break, cut)
Str::initials($s, $capitalize)str::initials(s) or str::initials_with(s, capitalize)s|str_initials(capitalize)
Str::apa($s)str::apa(s)s|str_apa
Str::transliterate($s, $unknown, $strict)str::transliterate(s), str::transliterate_with(s, unknown) or str::transliterate_strict(s, unknown, intl)—
Str::toBase64($s)str::to_base64(s)—
Str::fromBase64($s, $strict)str::from_base64(s) or str::from_base64_with(s, strict)—
Str::flushCache()str::flush_cache()—
Str::match($pattern, $subject)str::match_first(pattern, subject)?s|str_match(pattern)
Str::isMatch($pattern, $value)str::is_match(pattern, value)? or str::is_match(&[pattern, other], value)?s|str_is_match(pattern)
Str::matchAll($pattern, $subject)str::match_all(pattern, subject)?—
Str::replaceMatches($pattern, $replacement, $subject)str::replace_matches(pattern, replacement, subject)?s|str_replace_matches(pattern, replacement)
Str::replaceMatches($pattern, $replacement, $subject, $limit)str::replace_matches_with_limit(pattern, replacement, subject, limit)?s|str_replace_matches(pattern, replacement, limit)
Str::replaceMatches($patterns, $replacements, $subject, $limit)str::replace_matches_many(patterns, replacements, subject, limit)?—
Str::replaceMatches($pattern, $callback, $subject, $limit)str::replace_matches_with(pattern, subject, limit, callback)?—
Str::markdown($text, $options)str::markdown(text) or str::markdown_with(text, &options)s|str_markdown
Str::inlineMarkdown($text, $options)str::inline_markdown(text) or str::inline_markdown_with(text, &options)s|str_inline_markdown
Str::random($length)str::random(length)?—
Str::password($length, $letters, $numbers, $symbols, $spaces)str::password()? or str::password_with(options)?—
Str::uuid()str::uuid()?—
Str::uuid7($time)str::uuid7(time)? or generator.uuid7(time)?—
Str::orderedUuid()str::ordered_uuid(time)?—
Str::ulid($time)str::ulid(time)? or generator.ulid(time)?—
Number::format($n)number::format(n)n|number_format_intl
Number::format($n, precision: $p)number::format_with(n, Precision::Exact(p))n|number_format_intl(precision=p)
Number::format($n, maxPrecision: $p)number::format_with(n, Precision::Max(p))n|number_format_intl(max_precision=p)
Number::fileSize($bytes)number::file_size(bytes)bytes|number_file_size
Number::fileSize($bytes, precision: $p)number::file_size_with(bytes, Precision::Exact(p))bytes|number_file_size(precision=p)
Number::percentage($n, precision: $p)number::percentage(n, p) or number::percentage_with(n, Precision::Exact(p))n|number_percentage(precision=p)
Number::currency($n, $code)number::currency(n, code)n|number_currency(code)
Number::currency($n, $code, 'en', $p)number::currency_with(n, code, number::IcuData::default(), Some(p))n|number_currency(code, p)
Number::abbreviate($n, precision: $p)number::abbreviate(n, p) or number::abbreviate_with(n, Precision::Exact(p))n|number_abbreviate(precision=p)
Number::forHumans($n, precision: $p)number::for_humans(n, p) or number::for_humans_with(n, Precision::Exact(p), false)n|number_for_humans(precision=p)
Number::ordinal($n)number::ordinal(n)n|number_ordinal
Number::trim($n)number::trim(n)—
Number::clamp($n, $min, $max)number::clamp(n, min, max)—
Number::pairs($to, $by)number::pairs(to, by)—
Number::pairs($to, $by, $start, $offset)number::pairs_with(to, by, start, offset)—
Number::spell($n)number::spell(n)n|number_spell
Number::spell($n, after: 2, until: 10)number::spell_with(n, Some(2), Some(10))n|number_spell(after=2, until=10)
Number::spell($n, locale: 'en_GB')locale.spell(n, None, None)? on an en_GB contextn|number_spell(locale="en_GB")
Number::spellOrdinal($n)number::spell_ordinal(n) or locale.spell_ordinal(n)?n|number_spell_ordinal(locale)
Number::ordinal($n, locale: 'en_GB')locale.ordinal(n)? on an en_GB contextn|number_ordinal(locale)
Number::spell($n, 'fr', $after, $until)locale.spell(n, after, until)?n|number_spell(locale="fr", after=after, until=until)
Number::spellOrdinal($n, 'de')locale.spell_ordinal(n)?n|number_spell_ordinal(locale="de")
Number::ordinal($n, 'es')locale.ordinal(n)?n|number_ordinal(locale="es")
Number::parse($s)number::parse(s)—
Number::parse($s, NumberFormatter::TYPE_INT32)number::parse_with(s, ParseType::Int32, icu)?—
Number::parseInt($s)number::parse_int(s)—
Number::parseFloat($s)number::parse_float(s)—
Number::parse($s, NumberFormatter::TYPE_DOUBLE, 'fr')locale.parse(s, ParseType::Float)—
Number::parseInt($s, 'fr')locale.parse_int(s)—
Number::parseFloat($s, 'fr')locale.parse_float(s)—
Number::format($n, locale: 'fr')locale.format(n, None) on a French contextn|number_format_intl(locale=locale)
Number::percentage($n, precision: 2, locale: 'fr')locale.percentage(n, Precision::Exact(2))n|number_percentage(2, locale=locale)
Number::currency($n, in: 'EUR', locale: 'fr')locale.currency(n, Some("EUR"), None)n|number_currency("EUR", locale=locale)
Number::useLocale('fr')Bind Locale::new("fr", icu)? to the request or caller's context—
Number::withLocale('fr', $callback)Pass Locale::new("fr", icu)? to the closure—
Number::defaultLocale()locale.id()—
Number::useCurrency('EUR')Bind locale.with_currency("EUR") as the caller's context—
Number::withCurrency('EUR', $callback)Pass locale.with_currency("EUR") to the closure—
Number::defaultCurrency()locale.default_currency()—
$date->format($pattern) / date($pattern, $unix)carbon::format(date, pattern), after constructing a Jiff date in the intended zonedate|carbon_format(pattern)
$date->toIso8601String()carbon::to_iso8601_string(date)date|carbon_iso8601
$date->toISOString()carbon::to_iso_string(date)date|carbon_iso_string
$date->toDateString()carbon::to_date_string(date)date|carbon_date_string
$date->toTimeString()carbon::to_time_string(date)date|carbon_format("H:i:s")
$date->toDateTimeString()carbon::to_date_time_string(date)date|carbon_format("Y-m-d H:i:s")
$date->toAtomString()carbon::to_atom_string(date)date|carbon_iso8601
$date->toRfc2822String()carbon::to_rfc2822_string(date)date|carbon_format("r")
$date->toFormattedDateString()carbon::to_formatted_date_string(date)date|carbon_format("M j, Y")
$date->toDayDateTimeString()carbon::to_day_date_time_string(date)date|carbon_format("D, M j, Y g:i A")
$date->toCookieString()carbon::to_cookie_string(date)date|carbon_format("l, d-M-Y H:i:s T")
$date->toRssString()carbon::to_rss_string(date)date|carbon_format("r")
$date->toW3cString()carbon::to_w3c_string(date)date|carbon_iso8601
Carbon::parse($text, $tz)carbon::parse(text, &tz, now)text|carbon_parse(tz=zone)
$date->modify($text)carbon::modify(date, text)date|carbon_modify(text)
strtotime($text, $baseTimestamp)php::strtotime(text, now, &tz)text|php_strtotime(base_timestamp, tz=zone)
date_create($text, $tz)php::date_create(text, &tz, now)carbon_parse(tz=zone) for the Carbon equivalent
Carbon::createFromFormat($format, $text, $tz)carbon::create_from_format(format, text, &tz)text|carbon_create_from_format(format, tz=zone)
Carbon::createFromTimestamp($seconds, $tz)carbon::create_from_timestamp(seconds, &tz)Pass seconds and tz= to the date filters
new CarbonInterval($spec)carbon::Interval::from_spec(spec)spec|interval_for_humans formats the interval
CarbonInterval::fromString($text)carbon::Interval::from_string(text)
$interval->cascade()->forHumans(['join' => true])interval.cascade()?.for_humans(&DiffForHumans::for_interval().join())spec|interval_for_humans(join=true, cascade=true)
$interval->format($pattern)interval.format(pattern)
$interval->spec()interval.spec()
$interval->total('hours')interval.total(CalendarUnit::Hour)
$date->diff($other)carbon::diff(date, other)
$date->diffAsCarbonInterval($other, $absolute)carbon::diff_as_carbon_interval(date, other, absolute)
CarbonPeriod::createFromIso($spec)carbon::Period::from_spec(spec)
$period->spec() / $period->toString()period.spec() / period.to_string()
$period->toArray()period.to_array()Pass the collected dates to the template
$date->shiftTimezone($zone)carbon::shift_timezone(date, zone)
$date->locale($locale)->startOfWeek() / endOfWeek()carbon::start_of_week_in(locale, date) / end_of_week_in(locale, date)
$date->week() / $date->weekOfYearcarbon::week_of_year_in(locale, date) / iso_week_of_year(date)
$date->toDateTimeString('minute')carbon::to_date_time_string_with(date, DateTimePrecision::Minute)date|carbon_date_time_string("minute")
$date->toISOString(true)carbon::to_iso_string_keep_offset(date)date|carbon_iso_string(keep_offset=true)
$date->locale($code)->diffForHumans(['parts' => 2, 'join' => true])DiffForHumans::new().locale(locale).parts(2).join().apply(date, Relative::Now(now))date|diff_for_humans(parts=2, join=true, locale=code)
$date->diffForHumans()carbon::diff_for_humans(date, Relative::Now(now))date|diff_for_humans in an application context
$date->diffForHumans($other)carbon::diff_for_humans(date, Relative::To(&other))date|diff_for_humans(other=other)
$date->diffForHumans(['parts' => 2, 'join' => true])carbon::DiffForHumans::new().parts(2).join().apply(date, Relative::Now(now))date|diff_for_humans(parts=2, join=true)
$date->locale($code)carbon::Locale::new(code) selects the locale passed to _in helpers—
$date->locale()locale.code() returns the resolved code—
$date->isoFormat($pattern)carbon::iso_format(date, pattern)date|carbon_iso_format(pattern, locale)
$date->locale($code)->isoFormat($pattern)carbon::iso_format_in(locale, date, pattern)date|carbon_iso_format(pattern, locale)
$date->translatedFormat($pattern)carbon::translated_format(date, pattern)date|carbon_translated_format(pattern, locale)
$date->locale($code)->translatedFormat($pattern)carbon::translated_format_in(locale, date, pattern)date|carbon_translated_format(pattern, locale)
$date->calendar($reference)carbon::calendar(date, reference)date|carbon_calendar(reference, locale)
$date->locale($code)->calendar($reference)carbon::calendar_in(locale, date, reference)date|carbon_calendar(reference, locale)
$date->locale($code)->diffForHumans($other)carbon::diff_for_humans_in(locale, date, Relative::To(&other))date|carbon_diff_for_humans_in(other, locale)
$date->locale($code)->diffForHumans()carbon::diff_for_humans_in(locale, date, Relative::Now(now))date|diff_for_humans(locale=code)
$date->addMicroseconds($value)carbon::add_microseconds(date, value)—
$date->addMilliseconds($value)carbon::add_milliseconds(date, value)—
$date->addSeconds($value)carbon::add_seconds(date, value)—
$date->addMinutes($value)carbon::add_minutes(date, value)—
$date->addHours($value)carbon::add_hours(date, value)—
$date->addDays($value)carbon::add_days(date, value)—
$date->addWeeks($value)carbon::add_weeks(date, value)—
$date->addMonths($value)carbon::add_months(date, value)—
$date->addMonthsNoOverflow($value)carbon::add_months_no_overflow(date, value)—
$date->addMonthsWithOverflow($value)carbon::add_months_with_overflow(date, value)—
$date->addQuarters($value)carbon::add_quarters(date, value)—
$date->addQuartersNoOverflow($value)carbon::add_quarters_no_overflow(date, value)—
$date->addQuartersWithOverflow($value)carbon::add_quarters_with_overflow(date, value)—
$date->addYears($value)carbon::add_years(date, value)—
$date->addYearsNoOverflow($value)carbon::add_years_no_overflow(date, value)—
$date->addYearsWithOverflow($value)carbon::add_years_with_overflow(date, value)—
$date->addDecades($value)carbon::add_decades(date, value)—
$date->addDecadesNoOverflow($value)carbon::add_decades_no_overflow(date, value)—
$date->addDecadesWithOverflow($value)carbon::add_decades_with_overflow(date, value)—
$date->addCenturies($value)carbon::add_centuries(date, value)—
$date->addCenturiesNoOverflow($value)carbon::add_centuries_no_overflow(date, value)—
$date->addCenturiesWithOverflow($value)carbon::add_centuries_with_overflow(date, value)—
$date->addMillennia($value)carbon::add_millennia(date, value)—
$date->addMillenniaNoOverflow($value)carbon::add_millennia_no_overflow(date, value)—
$date->addMillenniaWithOverflow($value)carbon::add_millennia_with_overflow(date, value)—
$date->addWeekdays($value)carbon::add_weekdays(date, value)—
$date->addUnit($unit, $value)carbon::add_unit(date, unit, value)—
$date->addUnit($unit, $value, $overflow)carbon::add_unit_with_overflow(date, unit, value, overflow)—
$date->add($interval)carbon::add_span(date, span)—
$date->subMicroseconds($value)carbon::sub_microseconds(date, value)—
$date->subMilliseconds($value)carbon::sub_milliseconds(date, value)—
$date->subSeconds($value)carbon::sub_seconds(date, value)—
$date->subMinutes($value)carbon::sub_minutes(date, value)—
$date->subHours($value)carbon::sub_hours(date, value)—
$date->subDays($value)carbon::sub_days(date, value)—
$date->subWeeks($value)carbon::sub_weeks(date, value)—
$date->subMonths($value)carbon::sub_months(date, value)—
$date->subMonthsNoOverflow($value)carbon::sub_months_no_overflow(date, value)—
$date->subMonthsWithOverflow($value)carbon::sub_months_with_overflow(date, value)—
$date->subQuarters($value)carbon::sub_quarters(date, value)—
$date->subQuartersNoOverflow($value)carbon::sub_quarters_no_overflow(date, value)—
$date->subQuartersWithOverflow($value)carbon::sub_quarters_with_overflow(date, value)—
$date->subYears($value)carbon::sub_years(date, value)—
$date->subYearsNoOverflow($value)carbon::sub_years_no_overflow(date, value)—
$date->subYearsWithOverflow($value)carbon::sub_years_with_overflow(date, value)—
$date->subDecades($value)carbon::sub_decades(date, value)—
$date->subDecadesNoOverflow($value)carbon::sub_decades_no_overflow(date, value)—
$date->subDecadesWithOverflow($value)carbon::sub_decades_with_overflow(date, value)—
$date->subCenturies($value)carbon::sub_centuries(date, value)—
$date->subCenturiesNoOverflow($value)carbon::sub_centuries_no_overflow(date, value)—
$date->subCenturiesWithOverflow($value)carbon::sub_centuries_with_overflow(date, value)—
$date->subMillennia($value)carbon::sub_millennia(date, value)—
$date->subMillenniaNoOverflow($value)carbon::sub_millennia_no_overflow(date, value)—
$date->subMillenniaWithOverflow($value)carbon::sub_millennia_with_overflow(date, value)—
$date->subWeekdays($value)carbon::sub_weekdays(date, value)—
$date->subUnit($unit, $value)carbon::sub_unit(date, unit, value)—
$date->subUnit($unit, $value, $overflow)carbon::sub_unit_with_overflow(date, unit, value, overflow)—
$date->sub($interval)carbon::sub_span(date, span)—
$date->diffInMicroseconds($other)carbon::diff_in_microseconds(date, other)—
$date->diffInMicroseconds($other, $absolute, $utc)carbon::diff_in_microseconds_with(date, other, options)—
$date->diffInMilliseconds($other)carbon::diff_in_milliseconds(date, other)—
$date->diffInMilliseconds($other, $absolute, $utc)carbon::diff_in_milliseconds_with(date, other, options)—
$date->diffInSeconds($other)carbon::diff_in_seconds(date, other)—
$date->diffInSeconds($other, $absolute, $utc)carbon::diff_in_seconds_with(date, other, options)—
$date->diffInMinutes($other)carbon::diff_in_minutes(date, other)—
$date->diffInMinutes($other, $absolute, $utc)carbon::diff_in_minutes_with(date, other, options)—
$date->diffInHours($other)carbon::diff_in_hours(date, other)—
$date->diffInHours($other, $absolute, $utc)carbon::diff_in_hours_with(date, other, options)—
$date->diffInDays($other)carbon::diff_in_days(date, other)—
$date->diffInDays($other, $absolute, $utc)carbon::diff_in_days_with(date, other, options)—
$date->diffInWeeks($other)carbon::diff_in_weeks(date, other)—
$date->diffInWeeks($other, $absolute, $utc)carbon::diff_in_weeks_with(date, other, options)—
$date->diffInMonths($other)carbon::diff_in_months(date, other)—
$date->diffInMonths($other, $absolute, $utc)carbon::diff_in_months_with(date, other, options)—
$date->diffInQuarters($other)carbon::diff_in_quarters(date, other)—
$date->diffInQuarters($other, $absolute, $utc)carbon::diff_in_quarters_with(date, other, options)—
$date->diffInYears($other)carbon::diff_in_years(date, other)—
$date->diffInYears($other, $absolute, $utc)carbon::diff_in_years_with(date, other, options)—
$date->diffInWeekdays($other)carbon::diff_in_weekdays(date, other)—
$date->diffInWeekdays($other, $absolute, $utc)carbon::diff_in_weekdays_with(date, other, options)—
$date->diffInWeekendDays($other)carbon::diff_in_weekend_days(date, other)—
$date->diffInWeekendDays($other, $absolute, $utc)carbon::diff_in_weekend_days_with(date, other, options)—
$date->diffInUnit($unit, $other, $absolute, $utc)carbon::diff_in_unit(date, other, unit, options)—
$date->diffIn*($other, absolute: true)DifferenceOptions::default().absolute(true)—
$date->diffIn*($other, utc: true)DifferenceOptions::default().utc(true)—
$date->startOfMillisecond()carbon::start_of_millisecond(date)—
$date->startOfSecond()carbon::start_of_second(date)—
$date->startOfMinute()carbon::start_of_minute(date)—
$date->startOfHour()carbon::start_of_hour(date)—
$date->startOfDay()carbon::start_of_day(date)—
$date->startOfWeek()carbon::start_of_week(date)—
$date->startOfMonth()carbon::start_of_month(date)—
$date->startOfQuarter()carbon::start_of_quarter(date)—
$date->startOfYear()carbon::start_of_year(date)—
$date->startOfDecade()carbon::start_of_decade(date)—
$date->startOfCentury()carbon::start_of_century(date)—
$date->startOfMillennium()carbon::start_of_millennium(date)—
$date->startOf($unit)carbon::start_of_unit(date, unit)—
$date->startOfWeek($weekday)carbon::start_of_week_on(date, weekday)—
$date->isStartOfDay()carbon::is_start_of_day(date)—
$date->isStartOfDay($checkMicroseconds)carbon::is_start_of_day_with_precision(date, check_microseconds)—
$date->isStartOfDay(interval: $interval)carbon::is_start_of_day_with_interval(date, span)—
$date->endOfMillisecond()carbon::end_of_millisecond(date)—
$date->endOfSecond()carbon::end_of_second(date)—
$date->endOfMinute()carbon::end_of_minute(date)—
$date->endOfHour()carbon::end_of_hour(date)—
$date->endOfDay()carbon::end_of_day(date)—
$date->endOfWeek()carbon::end_of_week(date)—
$date->endOfMonth()carbon::end_of_month(date)—
$date->endOfQuarter()carbon::end_of_quarter(date)—
$date->endOfYear()carbon::end_of_year(date)—
$date->endOfDecade()carbon::end_of_decade(date)—
$date->endOfCentury()carbon::end_of_century(date)—
$date->endOfMillennium()carbon::end_of_millennium(date)—
$date->endOf($unit)carbon::end_of_unit(date, unit)—
$date->endOfWeek($weekday)carbon::end_of_week_on(date, weekday)—
$date->isEndOfDay()carbon::is_end_of_day(date)—
$date->isEndOfDay($checkMicroseconds)carbon::is_end_of_day_with_precision(date, check_microseconds)—
$date->isEndOfDay(interval: $interval)carbon::is_end_of_day_with_interval(date, span)—
$date->eq($other)carbon::eq(date, other)—
$date->ne($other)carbon::ne(date, other)—
$date->gt($other)carbon::gt(date, other)—
$date->gte($other)carbon::gte(date, other)—
$date->lt($other)carbon::lt(date, other)—
$date->lte($other)carbon::lte(date, other)—
$date->min($other)carbon::min(date, other)—
$date->max($other)carbon::max(date, other)—
$date->average($other)carbon::average(date, other)—
$date->isBirthday($other)carbon::is_birthday(date, other)—
$date->between($a, $b, $inclusive)carbon::between(date, a, b, inclusive)—
$date->betweenIncluded($a, $b)carbon::between_included(date, a, b)—
$date->betweenExcluded($a, $b)carbon::between_excluded(date, a, b)—
$date->closest($a, $b)carbon::closest(date, a, b)—
$date->farthest($a, $b)carbon::farthest(date, a, b)—
$date->isSameMicrosecond($other)carbon::is_same_microsecond(date, other)—
$date->isSameMillisecond($other)carbon::is_same_millisecond(date, other)—
$date->isSameSecond($other)carbon::is_same_second(date, other)—
$date->isSameMinute($other)carbon::is_same_minute(date, other)—
$date->isSameHour($other)carbon::is_same_hour(date, other)—
$date->isSameDay($other)carbon::is_same_day(date, other)—
$date->isSameWeek($other)carbon::is_same_week(date, other)—
$date->isSameMonth($other)carbon::is_same_month(date, other)—
$date->isSameQuarter($other)carbon::is_same_quarter(date, other)—
$date->isSameYear($other)carbon::is_same_year(date, other)—
$date->isSameDecade($other)carbon::is_same_decade(date, other)—
$date->isSameCentury($other)carbon::is_same_century(date, other)—
$date->isSameMillennium($other)carbon::is_same_millennium(date, other)—
$date->isSameUnit($unit, $other)carbon::is_same_unit(date, other, unit)—
$date->isSameMonth($other, $ofSameYear)carbon::is_same_month_with_year(date, other, of_same_year)—
$date->isSameQuarter($other, $ofSameYear)carbon::is_same_quarter_with_year(date, other, of_same_year)—
$date->isWeekday()carbon::is_weekday(date)—
$date->isWeekend()carbon::is_weekend(date)—
$date->isMonday()carbon::is_monday(date)—
$date->isTuesday()carbon::is_tuesday(date)—
$date->isWednesday()carbon::is_wednesday(date)—
$date->isThursday()carbon::is_thursday(date)—
$date->isFriday()carbon::is_friday(date)—
$date->isSaturday()carbon::is_saturday(date)—
$date->isSunday()carbon::is_sunday(date)—
$date->isLeapYear()carbon::is_leap_year(date)—
$date->isLongYear()carbon::is_long_year(date)—
$date->isLongIsoYear()carbon::is_long_iso_year(date)—
$date->isLastOfMonth()carbon::is_last_of_month(date)—
$date->isToday()carbon::is_today(date, now)—
$date->isTomorrow()carbon::is_tomorrow(date, now)—
$date->isYesterday()carbon::is_yesterday(date, now)—
$date->isPast()carbon::is_past(date, now)—
$date->isFuture()carbon::is_future(date, now)—
$date->isNowOrPast()carbon::is_now_or_past(date, now)—
$date->isNowOrFuture()carbon::is_now_or_future(date, now)—
$date->isCurrentMicrosecond()carbon::is_current_microsecond(date, now)—
$date->isCurrentMillisecond()carbon::is_current_millisecond(date, now)—
$date->isCurrentSecond()carbon::is_current_second(date, now)—
$date->isCurrentMinute()carbon::is_current_minute(date, now)—
$date->isCurrentHour()carbon::is_current_hour(date, now)—
$date->isCurrentDay()carbon::is_current_day(date, now)—
$date->isCurrentWeek()carbon::is_current_week(date, now)—
$date->isCurrentMonth()carbon::is_current_month(date, now)—
$date->isCurrentQuarter()carbon::is_current_quarter(date, now)—
$date->isCurrentYear()carbon::is_current_year(date, now)—
$date->isCurrentDecade()carbon::is_current_decade(date, now)—
$date->isCurrentCentury()carbon::is_current_century(date, now)—
$date->isCurrentMillennium()carbon::is_current_millennium(date, now)—
$date->isCurrentUnit($unit)carbon::is_current_unit(date, now, unit)—
$date->isNextMicrosecond()carbon::is_next_microsecond(date, now)—
$date->isNextMillisecond()carbon::is_next_millisecond(date, now)—
$date->isNextSecond()carbon::is_next_second(date, now)—
$date->isNextMinute()carbon::is_next_minute(date, now)—
$date->isNextHour()carbon::is_next_hour(date, now)—
$date->isNextDay()carbon::is_next_day(date, now)—
$date->isNextWeek()carbon::is_next_week(date, now)—
$date->isNextMonth()carbon::is_next_month(date, now)—
$date->isNextQuarter()carbon::is_next_quarter(date, now)—
$date->isNextYear()carbon::is_next_year(date, now)—
$date->isNextDecade()carbon::is_next_decade(date, now)—
$date->isNextCentury()carbon::is_next_century(date, now)—
$date->isNextMillennium()carbon::is_next_millennium(date, now)—
$date->isNext<Unit>()carbon::is_next_unit(date, now, unit)—
$date->isLastMicrosecond()carbon::is_last_microsecond(date, now)—
$date->isLastMillisecond()carbon::is_last_millisecond(date, now)—
$date->isLastSecond()carbon::is_last_second(date, now)—
$date->isLastMinute()carbon::is_last_minute(date, now)—
$date->isLastHour()carbon::is_last_hour(date, now)—
$date->isLastDay()carbon::is_last_day(date, now)—
$date->isLastWeek()carbon::is_last_week(date, now)—
$date->isLastMonth()carbon::is_last_month(date, now)—
$date->isLastQuarter()carbon::is_last_quarter(date, now)—
$date->isLastYear()carbon::is_last_year(date, now)—
$date->isLastDecade()carbon::is_last_decade(date, now)—
$date->isLastCentury()carbon::is_last_century(date, now)—
$date->isLastMillennium()carbon::is_last_millennium(date, now)—
$date->isLast<Unit>()carbon::is_last_unit(date, now, unit)—
$date->yearcarbon::year(date)—
$date->monthcarbon::month(date)—
$date->daycarbon::day(date)—
$date->hourcarbon::hour(date)—
$date->minutecarbon::minute(date)—
$date->secondcarbon::second(date)—
$date->microcarbon::micro(date)—
$date->millicarbon::milli(date)—
$date->dayOfWeekcarbon::day_of_week(date)—
$date->dayOfWeekIsocarbon::day_of_week_iso(date)—
$date->dayOfYearcarbon::day_of_year(date)—
$date->weekOfYearcarbon::week_of_year(date)—
$date->isoWeekcarbon::iso_week(date)—
$date->isoWeekYearcarbon::iso_week_year(date)—
$date->weekOfMonthcarbon::week_of_month(date)—
$date->weekNumberInMonthcarbon::week_number_in_month(date)—
$date->quartercarbon::quarter(date)—
$date->daysInMonthcarbon::days_in_month(date)—
$date->daysInYearcarbon::days_in_year(date)—
$date->daysInQuartercarbon::days_in_quarter(date)—
$date->timestampcarbon::timestamp(date)—
$date->agecarbon::age(date, now)—
$date->offsetcarbon::offset(date)—
$date->offsetHourscarbon::offset_hours(date)—
$date->dstcarbon::dst(date)—
$date->localcarbon::local(date, &default_zone)—
$date->utccarbon::utc(date)—
$date->timezoneNamecarbon::timezone_name(date)—
$date->decadecarbon::decade(date)—
$date->centurycarbon::century(date)—
$date->millenniumcarbon::millennium(date)—
$date->getTimestampMs()carbon::timestamp_ms(date)—
$date->getPreciseTimestamp() / 1_000_000carbon::timestamp_float(date)—
$date->format('T')carbon::tz_abbreviation(date)—
$date->next($weekday)carbon::next(date, weekday)—
$date->previous($weekday)carbon::previous(date, weekday)—
$date->firstOfMonth($weekday)carbon::first_of_month(date, Option<Weekday>)—
$date->lastOfMonth($weekday)carbon::last_of_month(date, Option<Weekday>)—
$date->nthOfMonth($nth, $weekday)carbon::nth_of_month(date, nth, weekday)—
$date->firstOfQuarter($weekday)carbon::first_of_quarter(date, Option<Weekday>)—
$date->lastOfQuarter($weekday)carbon::last_of_quarter(date, Option<Weekday>)—
$date->nthOfQuarter($nth, $weekday)carbon::nth_of_quarter(date, nth, weekday)—
$date->firstOfYear($weekday)carbon::first_of_year(date, Option<Weekday>)—
$date->lastOfYear($weekday)carbon::last_of_year(date, Option<Weekday>)—
$date->nthOfYear($nth, $weekday)carbon::nth_of_year(date, nth, weekday)—
$date->setDate($y, $m, $d)carbon::set_date(date, year, month, day)—
$date->setTime($h, $m, $s, $micro)carbon::set_time(date, hour, minute, second, microseconds)—
$date->setISODate($y, $w, $d)carbon::set_iso_date(date, year, week, day)—
$date->setTimezone($timezone)carbon::set_timezone(date, zone)—
$date->copy()carbon::copy(date)—

For Str::of($value)->append(...$parts) and prepend(...$parts), use str::append(value, &parts) or str::prepend(value, &parts). Their template filters take variadic positional arguments. Use number::Locale with file_size, abbreviate or for_humans for Number::withLocale, or pass locale= to the equivalent template filters.

Use Some(language) or None with the Rust slug builder. Pass the length of a PHP collection to the equivalent plural helper. For number APIs accepting maximum precision, use Precision::Max(p) or the filter’s max_precision=p.

Keep the intended zone and freeze the comparison time when comparing snapshots. See Dates for the Carbon builder and MiniJinja templates for filter arguments and escaping.

Not in this package

Translation helpers __(), trans_choice() and @lang belong to the framework’s translation layer. Collection callbacks, parse_url() and view IDs are outside this formatting package.

JSON decoding options are outside the current API.

Community package, not affiliated with Laravel.