# Moving Blade views from PHP Laravel to Laravel for Rust (oxblade)

> This guide moves one page, with its layout and a component, from a PHP Laravel app to a Laravel for Rust app that renders with oxblade. The markup stays as it…

- Package: oxblade (Laravel for Rust, alpha), crates: `oxblade`, `oxblade-laravel`, `oxblade-macros`, `oxblade-mail`, `oxblade-cli`
- Maintenance: active; Latest release: 0.2.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/oxblade), [crates.io](https://crates.io/crates/oxblade/0.2.0), [docs.rs](https://docs.rs/oxblade/0.2.0), [Changelog](https://oss.bowerbird.si/oxblade/docs/changelog/), [Contributing](https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/SECURITY.md)
- Based on: [Laravel Blade](https://github.com/illuminate/view): The template language this package implements: Blade's markup, directives and rendered HTML (illuminate/view, MIT).
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/oxblade/docs/migrating-from-php/
- Source: https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/docs/migrating-from-php.md

This guide moves one page, with its layout and a component, from a PHP Laravel app to a Laravel for Rust app that
renders with oxblade. The markup stays as it is; the PHP expressions inside it become Rust-style expressions, and the
data the page needs moves into a typed view model.

## What changes and what doesn't

Blade's markup and directives stay: `@extends`, `@section`, `@yield`, `@stack`, `@forelse`, components, slots and
attribute bags work as they do in Laravel, and oxblade renders the same HTML. What changes is the code between the
braces:

| PHP Blade | oxblade |
| --- | --- |
| `$post->title` | `post.title` |
| `@forelse ($posts as $post)` | `@forelse (post in posts)` |
| `Str::limit($text, 120)` | `str::limit(text, 120)` |
| `@props(['title', 'featured' => false])` | `@props(title, featured = false)` |
| `$attributes->class([...])` | `attributes.class([...])` |

Conditions must be booleans and nothing converts implicitly. Where a page needs PHP's exact behaviour, the `php::`
functions provide it; the migration command inserts them where it can't prove the Rust form is equivalent.

## 1. Install the command

```shellscript
cargo install --locked oxblade-cli --version 0.2.0
```

## 2. Migrate the views

Take this page from a PHP app, `resources/views/posts/index.blade.php`:

```blade
@extends('layouts.app')

@section('title', 'Posts')

@section('content')
    <h1>{{ __('Latest posts') }}</h1>

    @forelse ($posts as $post)
        <x-card :title="$post->title" :featured="$post->views > 1000">
            <p>{{ Str::limit($post->excerpt, 120) }}</p>
            <a href="{{ route('posts.show', $post) }}">{{ __('Read more') }}</a>
        </x-card>
    @empty
        <p>{{ __('No posts yet.') }}</p>
    @endforelse

    <p>{{ trans_choice('{0} No comments|{1} One comment|[2,*] :count comments', $commentCount) }}</p>
@endsection
```

Its layout prints `{{ app()->getLocale() }}` in the `<html lang>` attribute, and `components/card.blade.php` is an
anonymous component with a `title` and a `featured` prop.

Run the command on the views directory:

```shellscript
oxblade migrate resources/views --out next/resources/views --report migrate-report.json
```

```
3 files, 20 converted, 1 pending
```

The page converts completely:

```blade
@forelse (post in posts)
    <x-card :title="post.title" :featured="post.views > 1000">
        <p>{{ str::limit(post.excerpt, 120) }}</p>
        <a href="{{ route('posts.show', post) }}">{{ __('Read more') }}</a>
    </x-card>
@empty
    <p>{{ __('No posts yet.') }}</p>
@endforelse

<p>{{ trans_choice('{0} No comments|{1} One comment|[2,*] :count comments', comment_count) }}</p>
```

So does the component:

```blade
@props(title, featured = false)

<article {{ attributes.class(['card', 'card--featured' => php::boolval(featured)]) }}>
    <h2>{{ title }}</h2>
    {{ slot }}
</article>
```

A default shows only one value a prop can take, so the command doesn't fix `featured`'s type from it. Because the prop
is untyped, it keeps PHP's truthiness with `php::boolval`; step 3 declares the type and removes it.

The one pending item is the layout's `app()->getLocale()`. A Rust view can't call into PHP's service container, so the
command leaves a marker that fails loudly instead of guessing:

```blade
<html lang="{{ todo('static-call: map the service in [shared] or inject a Rust service with @inject. …') }}">
```

`migrate-report.json` lists every marker with its file, line and the original PHP.

## 3. Map what the command can't know

Values that came from PHP services become shared data, and types the command couldn't infer from the template are
declared. Put both in `oxblade-migrate.toml` and run the command again:

```toml
[shared]
"app()->getLocale()" = "locale"

[types]
"posts[].views" = "int"
comment_count = "int"
featured = "bool"
```

```shellscript
oxblade migrate resources/views --out next/resources/views --config oxblade-migrate.toml
```

```
3 files, 21 converted, 0 pending
```

The layout now reads `<html lang="{{ locale }}">`, and the component declares `@props(title, featured: bool = false)`
with a plain `'card--featured' => featured`. Your app shares `locale` with every view, for example from a
middleware with `laravel::view::share`.

## 4. Write the view model

Next to each view the command writes a `.blade.rs` skeleton listing the data the template reads:

```rust
#[derive(Serialize, oxblade::Shape, oxblade::View)]
#[view("posts.index")]
pub struct PostsIndexView {
    pub comment_count: i64,
    pub posts: Vec<serde_json::Value>,
}
```

Give the loose parts real types, and move the queries the PHP controller ran into the handler that builds the model:

```rust
use serde::Serialize;

#[derive(Serialize, oxblade::Shape)]
pub struct PostCard {
    pub id: u64,
    pub title: String,
    pub excerpt: String,
    pub views: u64,
}

#[derive(Serialize, oxblade::Shape, oxblade::View)]
#[view("posts.index")]
pub struct PostsIndexView {
    pub posts: Vec<PostCard>,
    pub comment_count: i64,
}

pub async fn index() -> laravel::Result<laravel::view::View> {
    let posts = load_posts().await?; // your query
    let comment_count = count_comments().await?;
    oxblade_laravel::view(PostsIndexView { posts, comment_count })
}
```

Typed models are what `blade:check` reads: it validates every template against the fields and types of the model that
renders it, so a renamed field or a wrong type fails in CI instead of on a page.

## 5. Translations

Convert the app's PHP language files to the JSON files the adapter loads:

```shellscript
oxblade lang lang --out next/lang
```

`__()`, `trans_choice()`, `@lang` and `@choice` then render from them with Laravel's replacements and plural rules.

## 6. Check and render

Register the engine (see [getting started](https://oss.bowerbird.si/oxblade/docs/getting-started/)), then check every view:

```shellscript
cargo run -- blade:check
```

The check reports any remaining marker, any field a template reads that the model doesn't have, and type mismatches
such as a non-boolean condition. When it passes, render the page and compare it with the PHP app's HTML. For the views
oxblade's conformance suite covers, the bytes match; [getting started](https://oss.bowerbird.si/oxblade/docs/getting-started/#when-something-renders-differently)
lists the documented differences.

## When PHP keeps changing

If the PHP app is still being developed while you migrate, replay its later changes onto the converted views instead of
converting again. In a Git checkout, pass the two commits:

```shellscript
oxblade migrate --diff OLD..NEW resources/views --out next/resources/views
```

The command converts the PHP changes between those commits and applies them to the views you already migrated. It
exits unsuccessfully if a change conflicts with an edit you made; see the [CLI reference](https://oss.bowerbird.si/oxblade/docs/cli/).
