DEDUPED Hot AI repos. Real use cases. What people build. Get the Monday 5

How to save typed decisions in an Eloquent JSON column with Laya PHP

Cast a model attribute to a decision class so the result reads back as a typed object.

Short answer: Run composer require marcreichel/laya-php in your Laravel app; then add 'triage' => AsDecision::of(Triage::class) to the model's casts() method, with a JSON column named triage; Assign the result with $ticket->triage = $laya->decide($ticket->body, Triage::class); and call $ticket->save();. All steps.

Who it is forA Laravel developer who wants to keep each classification result on the record it describes, without writing parsing code.

The problemStoring classification output as loose arrays loses the enum and type information, and every read needs manual conversion.

The outcomeThe model attribute holds a typed decision, and it reads back with enums and floats intact.

What you need first

  • PHP 8.4+ and Composer
  • A PSR-18 HTTP client such as Guzzle or Symfony HttpClient
  • Docker, to run laya-serve from the repo's compose.yaml
  • Laravel 13+ for the Laravel steps (service provider, artisan commands, validation rule, cast)

Steps

  1. Run composer require marcreichel/laya-php in your Laravel app.
  2. Add 'triage' => AsDecision::of(Triage::class) to the model's casts() method, with a JSON column named triage.
  3. Assign the result with $ticket->triage = $laya->decide($ticket->body, Triage::class); and call $ticket->save();.
  4. Read a field back with $ticket->triage->department; to confirm it returns the enum case.

Prompt for your agent

In the marcreichel/laya-php repo, add an AsDecision cast for <decision class> on the <model> model's <json column>. Save one decision, reload the model and report the stored JSON and the read-back enum value. Verify that assigning a non-decision value throws InvalidDecisionCastException.

Caveat. Null attributes are stored as null, and lists and floats round-trip, but a JSON value with a missing key or an unknown enum value throws an exception.

Use this in your AI agent

Ask your agent

Using the Deduped MCP, get the setup steps for marcreichel/laya-php and "Save typed decisions in an Eloquent JSON column"

Add Deduped to Claude Code once

claude mcp add --transport http deduped https://dedupedai.com/mcp

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer