# Laravel integration (laravel-rust-format)

> Install laravel-rust-format alongside Laravel for Rust 0.2 (>=0.2.0, <0.3). The default minijinja feature enables the framework’s MiniJinja integration.

- Package: laravel-rust-format (Laravel for Rust, alpha), crates: `laravel-rust-format`, `laravel-rust-format-core`
- Maintenance: active; Latest release: 0.1.1 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-format), [crates.io](https://crates.io/crates/laravel-rust-format/0.1.1), [docs.rs](https://docs.rs/laravel-rust-format/0.1.1), [Changelog](https://oss.bowerbird.si/format/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/SECURITY.md)
- Based on: [Laravel Str, Number and Pluralizer](https://github.com/laravel/framework): The behaviour of Illuminate\Support\Str, Number and Pluralizer, as typed Rust functions with English defaults.; [Carbon](https://github.com/briannesbitt/Carbon): The calendar, formats and relative-time translations, on Jiff with an explicit clock instant. The generated locale tables credit the authors of each language file.; [Doctrine Inflector](https://github.com/doctrine/inflector): English inflection rules, generated into Rust tables.; [Portable ASCII](https://github.com/voku/portable-ascii): Transliteration tables for Str::ascii and Str::slug, generated into Rust tables.; [League CommonMark](https://github.com/thephpleague/commonmark): Reference behaviour for Markdown in the PHP oracle; Comrak renders Markdown in Rust.; [Ramsey UUID](https://github.com/ramsey/uuid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.; [Symfony UID](https://github.com/symfony/uid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.
- PHP parity: core (465 covered, 4 diverged, 3 planned of 472 abilities; 133,206 fixtures; follows illuminate/support 13.39.0; verified 2026-12-04)
- Used in production across multiple projects.
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/format/docs/laravel-integration/
- Source: https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/docs/laravel-integration.md

Install `laravel-rust-format` alongside Laravel for Rust `0.2` (`>=0.2.0, <0.3`). The default `minijinja` feature enables the framework’s MiniJinja integration.

## Register the provider

Add `FormattingServiceProvider` to the application builder. This is a fragment for an app’s configuration.

```rust
use laravel::Application;
use laravel_rust_format::{FormattingConfig, FormattingServiceProvider};

let _builder = Application::configure()
    .with_providers(|providers| {
        providers.add(FormattingServiceProvider);
    })
    .with_config(|config, _| {
        config.section_mut::<FormattingConfig>().currency = "EUR".into();
    });
```

The optional `with_config` callback above overrides the currency in Rust. You can also set defaults in the app environment.

| Variable | Default | Used by |
| --- | --- | --- |
| `FORMATTING_CURRENCY` | `USD` | `number_currency` when the code is omitted, empty or `"0"` |
| `FORMATTING_TIMEZONE` | `UTC` | Timestamp display in Carbon filters and the zone for `php_date` and the date constructors |
| `FORMATTING_MAX_OUTPUT_BYTES` | `8388608` | Raw formatter output before MiniJinja autoescaping |
| `FORMATTING_MAX_COLLECTION_ITEMS` | `100000` | Template collection output, including nested entries |

The provider discovers `FormattingConfig` and validates its ISO 4217 currency code and time zone at boot. The number and relative-time helpers default to English and accept explicit locales. The template configuration is separate from the core’s explicit arguments and from the application’s own time zone.

Set `FormattingConfig::limits` to a core `php::Limits` value to configure budgets from Rust. Core functions accepting limits can reject oversized allocations during formatting. Other outputs are checked when the adapter receives them.

## Use the application clock

Inside a Laravel request or application test context, `diff_for_humans` reads `laravel::now()` when `other` is omitted. Use `app.travel(duration)` or `app.travel_to(timestamp)` in a Laravel test to control that instant. An explicit `other` compares with the supplied date and uses Carbon’s comparison wording by default.

## Use the helpers without the provider

Rust functions work by importing `laravel_rust_format::{php, str, number, carbon, js}` or the same modules from the core crate. For a standalone MiniJinja environment, register the filters directly using the framework’s MiniJinja re-export. Use `FormattingConfig::default()` or `FormattingConfig::new(currency, timezone)` and override its public fields as needed.

```rust
use laravel::view::minijinja::{Environment, context};
use laravel_rust_format::{FormattingConfig, register_filters};

let mut env = Environment::new();
register_filters(&mut env, &FormattingConfig::default());

let rendered = env.render_str(
    "{{ amount|number_format(2) }}",
    context! { amount => 1234.5 },
).unwrap();
assert_eq!(rendered, "1,234.50");
```

In a standalone environment, supply `other` to `diff_for_humans`. Disable the adapter’s default features if your app only needs the provider’s config and the Rust API. For projects without a Laravel for Rust dependency, install the core directly.

Community package, not affiliated with Laravel.
