# AI use cases for Laya PHP (marcreichel/laya-php)

Repo: [marcreichel/laya-php](https://github.com/marcreichel/laya-php) | Use cases: 4 | Page: https://dedupedai.com/use-cases/marcreichel-laya-php/

A PHP SDK for classifying text with Laya, a self-hosted multilingual decision engine that returns typed enums, ints and bools without an LLM API bill.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Route support tickets by department, urgency and churn risk: https://dedupedai.com/use-cases/marcreichel-laya-php/route-support-tickets/
- Block abusive or spam text in Laravel form submissions: https://dedupedai.com/use-cases/marcreichel-laya-php/gate-user-content-in-forms/
- Unit-test classification code without a running server: https://dedupedai.com/use-cases/marcreichel-laya-php/unit-test-classification-code/
- Save typed decisions in an Eloquent JSON column: https://dedupedai.com/use-cases/marcreichel-laya-php/store-decisions-in-json-column/

## How to route support tickets by department, urgency and churn risk with Laya PHP

Repo: [marcreichel/laya-php](https://github.com/marcreichel/laya-php) | Difficulty: Intermediate | Time: 1 hour | Basis: From the README

Send each incoming ticket to the right team on your own server, with a confidence check for human review.

**Who it is for:** A support lead or backend developer whose help desk needs every ticket sorted without sending customer text to a paid LLM API.

**The problem:** Tickets arrive unsorted, and manual triage is slow. Sending customer text to a hosted LLM costs per token and leaves your infrastructure.

**The outcome:** Each ticket gets a typed department, urgency and churn flag, and low-confidence answers are routed to a person.

### Steps

1. Run `composer require marcreichel/laya-php` in your PHP project.
2. Start the local server from a clone of this repo with `docker compose up -d --wait`, then check it with `php artisan laya:health` in a Laravel app.
3. Write a readonly decision class with enum fields for department and urgency and a bool for churn, then try it with `php artisan laya:try "App\Decisions\Triage" "Hi, we were billed twice for March. Refund it today or we cancel."`.
4. In your queued job, call `$laya->decide($ticket->body, Triage::class)` and save the department on the ticket.
5. Compare `answerConfidence` with a threshold you choose and send low-confidence tickets to a human queue.

### Prompt to paste into your agent

```text
Using the marcreichel/laya-php repo, add a readonly decision class for <ticket queue> with department, urgency and churn fields, and call Laya::decide on the ticket body. Report the typed result and its answerConfidence for a sample ticket, and verify that `php artisan laya:try` prints a hydrated value for that class.
```

### Caveat

The SDK targets laya-serve running upstream Laya v0.4.6, and the README says it has not been tested against the hosted Jev API.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/marcreichel-laya-php/route-support-tickets/

## How to block abusive or spam text in Laravel form submissions with Laya PHP

Repo: [marcreichel/laya-php](https://github.com/marcreichel/laya-php) | Difficulty: Intermediate | Time: 45 minutes | Basis: From the README

Add a validation rule that asks a yes/no question about each submitted text and rejects the bad ones.

**Who it is for:** A Laravel developer who accepts reviews, comments or messages from users and wants a moderation check on the server.

**The problem:** Free-text fields let in insults, spam and threats, and reviewing every submission by hand does not scale.

**The outcome:** Form submissions that answer yes to the moderation question fail validation with a friendly message, and the others pass.

### Steps

1. Run `composer require marcreichel/laya-php` in your Laravel app.
2. Start laya-serve with `docker compose up -d --wait` from a clone of this repo and confirm it with `php artisan laya:health`.
3. Add `Decides::not('Does the text contain insults, hate speech or threats?')` to the rule list for the text field in your `$request->validate()` call.
4. Set your own `validation.laya` message if the default one does not fit your app.
5. Test the form with `Laya::fake(['answer' => true])` so the rule fails without a running server. (inferred, check the README)

### Prompt to paste into your agent

```text
In the marcreichel/laya-php repo's Laravel setup, add a Decides::not rule with the question <moderation question> to the <form field> validation in <controller or form request>. Report which test inputs pass and fail, and verify that a request with a fake answer of true is rejected.
```

### Caveat

If laya-serve is unreachable or busy, the rule fails validation unless you add passWhenUnavailable(), so plan for that case.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/marcreichel-laya-php/gate-user-content-in-forms/

## How to unit-test classification code without a running server with Laya PHP

Repo: [marcreichel/laya-php](https://github.com/marcreichel/laya-php) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Run your tests against a built-in fake so CI does not need Laya or Docker.

**Who it is for:** A PHP developer whose code calls a classifier and whose CI pipeline should not depend on a model server.

**The problem:** Tests that call a live model server are slow, flaky and need extra infrastructure to run in CI.

**The outcome:** Tests run on any machine with PHP and Composer, and they check how your code handles each typed answer.

### Steps

1. Run `composer require marcreichel/laya-php` in your project.
2. Open `examples/05-testing-with-fake.php` in the cloned repo to see how the fake is set up.
3. Run `php examples/05-testing-with-fake.php` to confirm it works without a server. (inferred, check the README)
4. Create a fake with the answers your code expects, for example `Laya::fake(['department' => Department::Billing, 'urgency' => 2, 'churn' => true])` in Laravel.
5. Assert the call count with `$laya->assertPredictedCount(1);` in your test.

### Prompt to paste into your agent

```text
In the marcreichel/laya-php repo, write a test for <class that calls Laya> that uses the built-in fake to return <expected answers>. Report the test result and the call count, and verify that the test passes with no laya-serve running.
```

### Caveat

The fake only returns the answers you give it, so it checks your code's handling of results, not whether Laya would classify real text correctly.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/marcreichel-laya-php/unit-test-classification-code/

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

Repo: [marcreichel/laya-php](https://github.com/marcreichel/laya-php) | Difficulty: Intermediate | Time: 45 minutes | Basis: From the README

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

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

**The problem:** Storing classification output as loose arrays loses the enum and type information, and every read needs manual conversion.

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

### 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 to paste into your agent

```text
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.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/marcreichel-laya-php/store-decisions-in-json-column/
