# Migrating from PHP (laravel-rust-credit-card)

> Map calls from laravel-validation-rules/credit-card to the Rust types, including immutable card metadata and typed custom brand definitions.

- Package: laravel-rust-credit-card (Laravel for Rust, alpha), crates: `laravel-rust-credit-card`, `laravel-rust-credit-card-core`
- 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-credit-card), [crates.io](https://crates.io/crates/laravel-rust-credit-card/0.1.0), [docs.rs](https://docs.rs/laravel-rust-credit-card/0.1.0), [Changelog](https://oss.bowerbird.si/credit-card/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/SECURITY.md)
- Based on: [laravel-validation-rules/credit-card](https://github.com/laravel-validation-rules/credit-card): The PHP validation rules whose behaviour this package independently implements, following version 1.12.3.
- PHP parity: full (30 covered, 12 diverged, 0 planned of 42 abilities; 830 fixtures; follows laravel-validation-rules/credit-card 1.12.3; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/credit-card/docs/migrating-from-php/
- Source: https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/docs/migrating-from-php.md

Map calls from laravel-validation-rules/credit-card to the Rust types, including immutable card metadata and typed custom brand definitions.

| PHP | Rust |
| --- | --- |
| `Factory::makeFromNumber($number)` | `Card::parse(number)` |
| `new Visa($number)` or `setCardNumber($number)` | `Brand::Visa.parse(number)` |
| `$card->isValidCvc($cvc)` | `card.is_valid_cvc(cvc)` |
| `Card::isValidCvcLength($cvc, $lengths)` | `is_valid_cvc_length(cvc, lengths)` |
| `ExpirationDateValidator::validate($year, $month)` | `YearMonth::parse(year, month, today)` |
| `new CardNumber()` | `CardNumber::new()` |
| `new CardCvc($cardNumber)` | `CardCvc::for_number(number)` or `CardCvc::for_field("card_number")` |
| `new CardExpirationYear($month)` | `CardExpirationYear::month(month)` or `CardExpirationYear::month_field("month")` |
| `new CardExpirationMonth($year)` | `CardExpirationMonth::year(year)` or `CardExpirationMonth::year_field("year")` |
| `new CardExpirationDate('m/y')` | `CardExpirationDate::new("m/y")` |
| `Cards\Discovery` | `Brand::Discover` |
| Custom card subclass | `CardSpec::builder(...)` |

Rust strips ASCII whitespace before detecting the brand. Its failures omit submitted values,
and rule messages are English by default. See the [rules guide](https://oss.bowerbird.si/credit-card/docs/rules/) for message overrides
and the application setting that keeps card fields out of browser sessions.

## Input differences

- A custom card specification requires nonempty PAN and CVC length lists containing positive
  integers. There is no package-imposed maximum.
- Split expiration validation accepts text and integers. The Laravel rules reject floats in both
  languages. A direct, coercive PHP call can also accept integral floats.
- A formatted expiration date preserves its parsed four-digit year. For example, PHP can
  reinterpret the year in `0026-12` as 2026 after parsing. The port treats year 0026 as outside
  the accepted range and reports an invalid expiration date.
