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
cargo install --locked oxblade-cli --version 0.2.02. Migrate the views
Take this page from a PHP app, resources/views/posts/index.blade.php:
@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:
oxblade migrate resources/views --out next/resources/views --report migrate-report.json3 files, 20 converted, 1 pending
The page converts completely:
@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:
@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:
<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:
[shared]
"app()->getLocale()" = "locale"
[types]
"posts[].views" = "int"
comment_count = "int"
featured = "bool"oxblade migrate resources/views --out next/resources/views --config oxblade-migrate.toml3 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:
#[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:
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:
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), then check every view:
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 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:
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.