Skip to content

Laravel examples

Short, realistic examples of using Tessero from a Laravel application.

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.

These show the shape of day-to-day use. Every example runs identically on both backends, backed by fully verified SciPy and NumPy parity. The full, runnable cookbook, generated from the library’s example manifest, lives under the docs.

A validated optimisation endpoint

use Tessero\Laravel\Facades\Tessero;
use Tessero\Laravel\Rules\NumericArray;

public function plan(Request $request)
{
    $data = $request->validate([
        'cost'   => ['required', new NumericArray(ndim: 1, maxElements: 1000)],
        'A_ub'   => ['required', new NumericArray(ndim: 2)],
        'b_ub'   => ['required', new NumericArray(ndim: 1)],
    ]);

    $plan = Tessero::linprog(
        c: $data['cost'], A_ub: $data['A_ub'], b_ub: $data['b_ub'],
    );

    abort_unless($plan['success'], 422, $plan['message']);

    return response()->json([
        'x'    => $plan['x'],          // optimal decision variables
        'cost' => $plan['fun'],
    ]);
}

Storing arrays on a model

use Tessero\Laravel\Casts\AsNDArray;

class Forecast extends Model
{
    protected $casts = [
        'covariance' => AsNDArray::class . ':binary',   // bit-exact
    ];
}

$f = Forecast::find(1);
$f->covariance->shape();     // read back as an NDArray
$f->covariance = $sigma;     // assign an NDArray, a PHP array, or null
$f->save();

Returning an array efficiently

// Body written straight from native memory via toJson()
return response()->ndarray($forecast->mean(0));

Built something with Tessero and Laravel? Add it to the showcase.