Migrate from Laravel to StrataPHP

Moving from Laravel to StrataPHP? This guide covers routes, Eloquent, middleware, and Blade. Migrating from Slim or Lumen instead? Use the sidebar to switch guides

You don't have to rewrite everything. StrataPHP speaks PSR standards, so most Laravel code ports directly.

Rule #1: Migrate one route at a time. Run Laravel and StrataPHP side-by-side until done.

1. Routing

Laravel and StrataPHP both use closure-based routing. Syntax is 95% the same.

Laravel

Route::get('/users', [UserController::class, 'index']);
Route::post('/users', [UserController::class, 'store'])
  ->middleware('auth');

StrataPHP

$router->get('/users', [UserController::class, 'index']);
$router->post('/users', [UserController::class, 'store'])
  ->middleware($auth);

Change: `Route::` becomes `$router->`. Middleware is PSR-15, not strings.

2. Controllers

No changes. Laravel controllers are plain PHP classes. Copy them over.

namespace App\Http\Controllers;

class UserController 
{
    public function index() {
        return ['users' => User::all()]; // Works in StrataPHP
    }
}

3. Database / Eloquent

Option A: Keep Eloquent

composer require illuminate/database

Boot it in `config/database.php`. All your models work unchanged.

Option B: Switch to strataphp/database

composer require strataphp/database
use StrataPHP\Database\Query;

$users = Query::table('users')->where('active', 1)->get();

4. Middleware

Laravel middleware implements PSR-15. It works in StrataPHP with zero changes.

namespace App\Http\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class AuthMiddleware implements MiddlewareInterface
{
    public function process(
        ServerRequestInterface $request, 
        RequestHandlerInterface $handler
    ): ResponseInterface {
        // Your Laravel auth logic here
        return $handler->handle($request);
    }
}

5. Blade Templates

Option A: Keep using Blade

composer require illuminate/view

Option B: Switch to Plates - recommended

composer require league/plates

Plates uses pure PHP. No compiling, no cache.

6. Running Both Frameworks Together

Use StrataPHP for new API routes. Keep Laravel for old web routes.

// public/index.php
if (str_starts_with($_SERVER['REQUEST_URI'], '/api/v2')) {
    require 'strataphp/public/index.php'; // StrataPHP
} else {
    require 'laravel/public/index.php'; // Laravel
}

What You Lose from Laravel

  • Facades — Use explicit DI instead: `new Mailer($config)`
  • Magic methods — `User::find()` becomes `$container->get(UserRepository::class)->find()`
  • Auto-wiring — Wire dependencies in `config/services.php`

What you gain: ~40ms faster per request, no hidden behavior, smaller vendor folder.

Need Help?

Stuck on a specific migration? Ask in Discord. We’ve migrated 3 Laravel apps to StrataPHP so far.

This guide covers basic Laravel apps. If you use Horizon, Nova, or Livewire heavily, migration is harder. StrataPHP is best for APIs and custom apps, not Laravel SPA clones.