Tessero for Laravel
The Tessero Laravel bridge wires Tessero into a Laravel application: a facade, Eloquent casts, a validation rule, a response macro, and Octane-safe runtime settings.
AI assistant
Build this with Claude Code, Cursor or Copilot
Copy a Tessero-tuned prompt for Laravel integration, grounded in 10 real API signatures , into your IDE's AI. No chatbot, just exact context.
Tessero is native numerical computing for the PHP you already write, with no call-out to a Python
service. The Laravel bridge, which ships inside tessero/tessero, wires its fully verified SciPy and NumPy parity into a
Laravel 12 or 13 application and is example-driven.
composer config repositories.tessero vcs https://github.com/DMJ-CV-91913/tessero
composer require tessero/tessero:dev-main
vendor/bin/tessero build
php artisan vendor:publish --tag=tessero-config # optional
php artisan tessero:doctor
The tessero:doctor command self-diagnoses your install, reporting the active backend, kernel
version, and BLAS and thread configuration so you can confirm Tessero is wired up before shipping.
libtessero
you build with vendor/bin/tessero build; the native extension is built from a source checkout.
The Laravel bridge uses the extension when it is loaded and falls back to FFI. Both
backends run one C kernel and return identical numbers. If no binary matches a host, calls report as
unavailable via tessero:doctor and Tessero::info() rather than returning wrong answers.
What you get
TesseroServiceProvider(auto-discovered): config, aTesseroManagersingleton, runtime settings, the response macro, andtessero:doctor.Tesserofacade:array,zeros,fromBytes,memmap,load,linprog,milp,solveMdp,normal,random,info,backend.Casts\AsNDArray: store an array in an Eloquent column and read it back as anNDArray.Rules\NumericArray: validate request input before it becomes an array.response()->ndarray($a): a JSON response written straight from native memory.
Eloquent casts
use Tessero\Laravel\Casts\AsNDArray;
class Forecast extends Model
{
protected $casts = [
'quantiles' => AsNDArray::class, // JSON nested arrays
'covariance' => AsNDArray::class . ':binary', // exact, compact
'features' => AsNDArray::class . ':binary,float32',
];
}
A json column round-trips to 17 significant digits; binary is bit-exact (including
NaN payloads and -0.0). Either format is read back regardless of the configured default, so you can
switch without migrating data.
Validating input
use Tessero\Laravel\Rules\NumericArray;
$data = $request->validate([
'prices' => ['required', new NumericArray(ndim: 1, maxElements: 8784)],
'weights' => ['required', new NumericArray(shape: [null, 3])], // n x 3
]);
$prices = Tessero::array($data['prices']);
The rule checks list arrays, a rectangular shape, the dimension count or exact shape, the element cap, and
that every leaf is a finite number. Always cap maxElements on public endpoints:
native memory is not counted by PHP’s memory_limit.
Queues & Octane
Runtime settings, threads, memory_budget, blas_threads and
epsilon, are applied at boot and re-applied at the start of every Octane request and
task, and before every queued job, so a long-lived worker never carries one request’s
settings into the next. Solver results from the facade are plain PHP arrays with the same keys on either
backend, so your controllers and jobs do not depend on which backend is installed. Dense matrix
multiplication routes through OpenBLAS at BLAS-class throughput, so the blas_threads setting
directly controls heavy linear-algebra performance in your workers.
Responses
return response()->ndarray($forecast->mean(0)); // 200, application/json
return response()->ndarray($matrix, 201, ['X-Model' => 'v3']);
See the examples, the full user guide, and submit what you build to the showcase.