# Migrating from PHP (laravel-rust-ogm)

> This page maps each ruudvdd/ogm call to its Rust equivalent and lists where the Rust behaviour differs on purpose.

- Package: laravel-rust-ogm (Laravel for Rust, alpha), crates: `laravel-rust-ogm`
- Maintenance: active; Latest release: 0.1.0 (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-ogm), [crates.io](https://crates.io/crates/laravel-rust-ogm/0.1.0), [docs.rs](https://docs.rs/laravel-rust-ogm/0.1.0), [Changelog](https://oss.bowerbird.si/ogm/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-ogm/blob/bf28d991039b0ea13ff1e66e4e57b32f8f82a805/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-ogm/blob/bf28d991039b0ea13ff1e66e4e57b32f8f82a805/SECURITY.md)
- Based on: [ruudvdd/ogm](https://github.com/ruudvdd/ogm): The Belgian structured payment reference package this ports: the generator, the validator and the mod-97 check, following version 0.2.0.
- PHP parity: full (4 covered, 5 diverged, 0 planned of 9 abilities; 55 fixtures; follows ruudvdd/ogm 0.2.0; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/ogm/docs/migrating-from-php/
- Source: https://github.com/bowerbird-si/laravel-rust-ogm/blob/bf28d991039b0ea13ff1e66e4e57b32f8f82a805/docs/migrating-from-php.md

This page maps each ruudvdd/ogm call to its Rust equivalent and lists where the Rust behaviour differs on purpose.

## Calls

| PHP | Rust |
| --- | --- |
| `(new Generator)->generate()` | `let ogm = Ogm::generate(); ogm.digits()` |
| `(new Generator)->generate(true)` | `Ogm::generate().to_string()` |
| `(new Generator)->generate(false, '2026')` | `let ogm = Ogm::generate_with_prefix("2026")?; ogm.digits()` |
| `(new Generator)->generate(true, '0909337554')` | `Ogm::from_base("0909337554")?.to_string()` |
| `TooMuchDigits` exception | `Err(OgmError::PrefixTooLong { .. })` |
| `(new Validator)->isValid($ogm)` | `is_valid_structured(ogm)` or `Ogm::from_structured(ogm)` |
| `(new Validator)->digitsAreValid($number)` | `digits_are_valid(number)` or `Ogm::from_digits(number)` |
| none | `Ogm::parse(input)` / `is_valid(input)`: any of the four forms, whitespace trimmed |
| `bin/ogm generate [PREFIX]` | no CLI; `Ogm::generate_with_prefix(prefix)?.to_string()` (formatted by default) |
| `bin/ogm generate -c [PREFIX]` | no CLI; `let ogm = Ogm::generate_with_prefix(prefix)?; ogm.digits()` |
| `bin/ogm validate OGM` | no CLI; `is_valid_structured(ogm)` |
| `bin/ogm validate -c OGM` | no CLI; `digits_are_valid(digits)` |

Rust returns an `Ogm` value instead of a string. Keep it as the type in your own code and format it
when you display or store it.

The random digits are not reproduced: the port does not use PHP's seeded `mt_rand` sequence. A 10-digit
prefix gives the same reference as PHP. With a shorter prefix, PHP's output and Rust's output each have
the right prefix and shape and pass the mod-97 check on their own; their random digits are unrelated and
are the same only by chance.

## Differences

Each one is a `diverged` row in the package's `parity.toml`.

- **`***XXX/XXXX/XXXXX***` is valid.** PHP's `isValid` rejects it because of a `str_replace` bug, although
  its docs list both delimiters. Rust accepts both.
- **No trailing newline in strict mode.** PHP's regex `$` matches before a final `\n`, so PHP accepts
  `"+++090/9337/55493+++\n"`. `from_structured` rejects it; `Ogm::parse` trims it.
- **Only ASCII digits.** PHP's `digitsAreValid` casts with `(int)`, so `abcdefghij97` passes. Rust
  returns `OgmError::InvalidCharacters`.
- **Prefix type and coercion.** PHP takes a string, int or `null` and throws `InvalidArgumentException` for
  other types, but silently coerces leading spaces (`" 123456789"` → `" 12345678939"`) and negative integers
  (`-123456789` → `"-123456789-39"`) without warning, and throws `TooMuchDigits` before coercion on
  overlength non-digit prefixes (`"1234567890x"`). Rust takes `&str`, checks ASCII digits before length,
  and returns `OgmError::InvalidPrefix` for any non-digit character. Use `Ogm::generate()` for no prefix.
- **No CLI.** The crate is a library only.
