PHPackages                             laravelplus/toon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravelplus/toon

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laravelplus/toon
================

Laravel package for TOON (Token-Oriented Object Notation) format with database and LLM support

v1.0.0(5mo ago)00MITPHPPHP ^8.4

Since Nov 23Pushed 5mo agoCompare

[ Source](https://github.com/LaravelPlus/toon)[ Packagist](https://packagist.org/packages/laravelplus/toon)[ RSS](/packages/laravelplus-toon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Laravel TOON Package
====================

[](#laravel-toon-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1081abe89abc235fb26c0c06aab3a89f050ce73a49fbf1aa14b72b16f39fd6b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c706c75732f746f6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelplus/toon)[![Total Downloads](https://camo.githubusercontent.com/21eb4fba6b1c3b85ca2660ea7a554e7850b7035b035bafdcca4483b2acfdd1fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c706c75732f746f6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelplus/toon)[![PHP Version](https://camo.githubusercontent.com/61399f4bb257fe5fa325b2104e12eb2245de0911c6c71453e9cbba7fff784e64/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342532422d626c75652e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/69ab28e033416eb531ab4644cda14302627d36bc18d3ef747feac9c26017e1e3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31322e782d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![License](https://camo.githubusercontent.com/6c711032aff1ca0eb6b211aa6cb3649ce7fd64a7714e1181d4bb457f9680e7cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Tests](https://camo.githubusercontent.com/c1047b585bc591b0050af011c8f05e00bf346241076c6c5cd7964153a42e39ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d706573742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://pestphp.com)[![Code Style](https://camo.githubusercontent.com/39e14fcc2c2d036ffa0b7cb37699ef26807bfc03a621877a296012a1089a8411/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d726563746f722d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://github.com/rectorphp/rector)

A Laravel package for **TOON (Token-Oriented Object Notation)** format with comprehensive database and LLM support. TOON is a compact, human-readable encoding of the JSON data model that minimizes tokens and makes structure easy for models to follow.

What is TOON?
-------------

[](#what-is-toon)

TOON combines YAML's indentation-based structure for nested objects with a CSV-style tabular layout for uniform arrays. It's optimized for **LLM input** as a drop-in, lossless representation of your existing JSON data.

**Example:**

```
{
  "users": [
    { "id": 1, "name": "Alice", "role": "admin" },
    { "id": 2, "name": "Bob", "role": "user" }
  ]
}
```

Becomes:

```
users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user

```

This reduces token count significantly while maintaining explicit structure that helps LLMs parse and validate data reliably.

**Another Example:**

Standard JSON:

```
{
  "products": [
    { "sku": "ABC123", "name": "Widget", "price": 29.99, "stock": 150 },
    { "sku": "XYZ789", "name": "Gadget", "price": 49.99, "stock": 75 },
    { "sku": "DEF456", "name": "Thing", "price": 19.99, "stock": 200 }
  ]
}
```

TOON format:

```
products[3]{name,price,sku,stock}:
  Widget,29.99,ABC123,150
  Gadget,49.99,XYZ789,75
  Thing,19.99,DEF456,200

```

The `[3]` declares the array length, `{name,price,sku,stock}` declares the field names once, and each row is a compact comma-separated list of values. This approach declares structure once and streams data compactly, approaching CSV's efficiency while adding explicit structure.

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Laravel 12.0 or higher

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require laravelplus/toon
```

The package will automatically register its service provider and facade.

Configuration
-------------

[](#configuration)

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=toon-config
```

This will create `config/toon.php` with the following options:

```
return [
    'encoding' => [
        'tabular_threshold' => 2,  // Minimum items for tabular format
        'max_depth' => 100,        // Maximum nesting depth
    ],
    'llm' => [
        'validate_array_lengths' => true,   // Validate [N] declarations
        'validate_field_counts' => true,    // Validate field counts
    ],
];
```

Usage
-----

[](#usage)

### Basic Encoding and Decoding

[](#basic-encoding-and-decoding)

#### Using Facade

[](#using-facade)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice', 'role' => 'admin'],
        ['id' => 2, 'name' => 'Bob', 'role' => 'user'],
    ],
];

// Encode to TOON format
$toon = Toon::encode($data);

// Decode back to array
$decoded = Toon::decode($toon);
```

#### Using Global Helper Function

[](#using-global-helper-function)

```
$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice', 'role' => 'admin'],
        ['id' => 2, 'name' => 'Bob', 'role' => 'user'],
    ],
];

// Fluent interface - pass data to toon()
$toon = toon($data)->encode();

// Or encode directly
$toon = toon()->encode($data);

// Decode
$decoded = toon($toon)->decode();

// Or decode directly
$decoded = toon()->decode($toon);
```

**Output:**

```
users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user

```

### Database Support

[](#database-support)

#### Eloquent Models

[](#eloquent-models)

```
use LaravelPlus\Toon\Facades\Toon;
use App\Models\User;

// Single model
$user = User::find(1);
$toon = Toon::fromEloquent($user);

// With relationships
$toon = Toon::fromEloquent($user, ['posts', 'comments']);

// Collection
$users = User::all();
$toon = Toon::fromEloquentCollection($users);

// Collection with relationships
$toon = Toon::fromEloquentCollection($users, ['profile']);
```

#### Using Helper Function

[](#using-helper-function)

```
use App\Models\User;

// Fluent interface
$user = User::find(1);
$toon = toon($user)->fromEloquent();

// With relationships
$toon = toon($user)->fromEloquent(['posts', 'comments']);

// Collection
$users = User::all();
$toon = toon($users)->fromEloquentCollection();

// Or without passing to toon()
$toon = toon()->fromEloquent($user);
```

#### Query Builder

[](#query-builder)

```
use LaravelPlus\Toon\Facades\Toon;

// Basic query
$toon = Toon::fromQueryBuilder(
    User::query()->where('active', true)
);

// With specific columns
$toon = Toon::fromQueryBuilder(
    User::query(),
    ['id', 'name', 'email']
);

// Chunked processing for large datasets
use LaravelPlus\Toon\Database\QueryBuilderToonConverter;

foreach (QueryBuilderToonConverter::toToonChunked(
    User::query(),
    chunkSize: 1000
) as $chunkToon) {
    // Process each chunk
    echo $chunkToon;
}
```

#### Collections

[](#collections)

```
use LaravelPlus\Toon\Facades\Toon;
use Illuminate\Support\Collection;

$collection = collect([
    ['id' => 1, 'name' => 'Alice'],
    ['id' => 2, 'name' => 'Bob'],
]);

$toon = Toon::fromCollection($collection);
```

### LLM Support

[](#llm-support)

#### Encoding for LLM Prompts

[](#encoding-for-llm-prompts)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice', 'score' => 95],
        ['id' => 2, 'name' => 'Bob', 'score' => 87],
    ],
];

// Encode with validation metadata
$toon = Toon::forLlm($data);

// Validate TOON string
$validation = Toon::validate($toon);
if ($validation['valid']) {
    // Use the TOON string
} else {
    foreach ($validation['errors'] as $error) {
        echo $error;
    }
}
```

#### Decoding LLM Responses

[](#decoding-llm-responses)

```
use LaravelPlus\Toon\Facades\Toon;

// Basic decoding
$llmResponse = "users[2]{id,name}:\n  1,Alice\n  2,Bob";
$data = Toon::fromLlm($llmResponse);

// Decode with validation
$result = Toon::fromLlmWithValidation($llmResponse);

if ($result['valid']) {
    $data = $result['data'];
} else {
    foreach ($result['errors'] as $error) {
        echo "Error: {$error}\n";
    }
}
```

#### Building LLM Prompts

[](#building-llm-prompts)

```
use LaravelPlus\Toon\Facades\Toon;

// Custom prompt
$prompt = Toon::prompt()
    ->system('You are a data analyst.')
    ->user('Analyze the user data and identify trends.')
    ->withData([
        'users' => User::all()->toArray(),
    ])
    ->build();

// Pre-built prompt types
$analysisPrompt = Toon::prompt()->forAnalysis(
    'What trends do you see in the data?',
    ['users' => User::all()->toArray()]
);

$transformationPrompt = Toon::prompt()->forTransformation(
    'Convert all names to uppercase',
    ['users' => User::all()->toArray()]
);

$extractionPrompt = Toon::prompt()->forExtraction(
    'Extract all email addresses',
    ['users' => User::all()->toArray()]
);
```

### Format Conversion

[](#format-conversion)

TOON supports conversion to and from multiple formats: JSON, XML, YAML, CSV, and XLSX.

#### TOON to JSON and Back

[](#toon-to-json-and-back)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ],
];

// Encode to TOON
$toon = Toon::encode($data);

// Convert TOON to JSON
$json = Toon::toJson($toon);

// Convert JSON back to TOON
$toonFromJson = Toon::fromJson($json);

// Using helper function
$json = toon($toon)->toJson();
$toon = toon($json)->fromJson();
```

#### TOON to XML and Back

[](#toon-to-xml-and-back)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ],
];

// Encode to TOON
$toon = Toon::encode($data);

// Convert TOON to XML
$xml = Toon::toXml($toon, rootElement: 'data');

// Convert XML back to TOON
$toonFromXml = Toon::fromXml($xml);

// Using helper function
$xml = toon($toon)->toXml(rootElement: 'data');
$toon = toon($xml)->fromXml();
```

#### TOON to YAML and Back

[](#toon-to-yaml-and-back)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ],
];

// Encode to TOON
$toon = Toon::encode($data);

// Convert TOON to YAML
$yaml = Toon::toYaml($toon, inline: 2, indent: 2);

// Convert YAML back to TOON
$toonFromYaml = Toon::fromYaml($yaml);

// Using helper function
$yaml = toon($toon)->toYaml();
$toon = toon($yaml)->fromYaml();
```

#### TOON to CSV and Back

[](#toon-to-csv-and-back)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice', 'role' => 'admin'],
        ['id' => 2, 'name' => 'Bob', 'role' => 'user'],
    ],
];

// Encode to TOON
$toon = Toon::encode($data);

// Convert TOON to CSV
$csv = Toon::toCsv($toon, delimiter: ',', includeHeaders: true);

// Convert CSV back to TOON
$toonFromCsv = Toon::fromCsv($csv);

// Using helper function
$csv = toon($toon)->toCsv();
$toon = toon($csv)->fromCsv();

// Custom CSV options
$csv = Toon::toCsv($toon, delimiter: ';', enclosure: "'", includeHeaders: false);
```

#### TOON to XLSX and Back

[](#toon-to-xlsx-and-back)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice', 'role' => 'admin'],
        ['id' => 2, 'name' => 'Bob', 'role' => 'user'],
    ],
];

// Encode to TOON
$toon = Toon::encode($data);

// Convert TOON to XLSX (returns base64 encoded string)
$xlsxBase64 = Toon::toXlsx($toon, includeHeaders: true, sheetName: 'Users');

// Save to file
file_put_contents('users.xlsx', base64_decode($xlsxBase64));

// Convert XLSX file back to TOON
$toonFromXlsx = Toon::fromXlsx('users.xlsx', sheetName: 'Users');

// Or use base64 encoded content
$toonFromXlsx = Toon::fromXlsx($xlsxBase64);

// Using helper function
$xlsx = toon($toon)->toXlsx(sheetName: 'Data');
$toon = toon('file.xlsx')->fromXlsx();
```

#### Direct Format Conversion

[](#direct-format-conversion)

```
use LaravelPlus\Toon\Converters\JsonConverter;
use LaravelPlus\Toon\Converters\XmlConverter;
use LaravelPlus\Toon\Converters\YamlConverter;
use LaravelPlus\Toon\Converters\CsvConverter;
use LaravelPlus\Toon\Converters\XlsxConverter;

// JSON to TOON
$json = '{"users":[{"id":1,"name":"Alice"}]}';
$toon = JsonConverter::fromJson($json);

// TOON to JSON
$json = JsonConverter::toJson($toon);

// XML to TOON
$xml = '1Alice';
$toon = XmlConverter::fromXml($xml);

// TOON to XML
$xml = XmlConverter::toXml($toon, rootElement: 'data');

// YAML to TOON
$yaml = "users:\n  - id: 1\n    name: Alice";
$toon = YamlConverter::fromYaml($yaml);

// TOON to YAML
$yaml = YamlConverter::toYaml($toon, inline: 2, indent: 2);

// CSV to TOON
$csv = "id,name,role\n1,Alice,admin\n2,Bob,user";
$toon = CsvConverter::fromCsv($csv);

// TOON to CSV
$csv = CsvConverter::toCsv($toon, includeHeaders: true);

// XLSX to TOON
$toon = XlsxConverter::fromXlsx('data.xlsx', sheetName: 'Sheet1');

// TOON to XLSX (returns base64 encoded string)
$xlsxBase64 = XlsxConverter::toXlsx($toon, includeHeaders: true, sheetName: 'Data');
```

### Advanced Examples

[](#advanced-examples)

#### Complex Nested Data

[](#complex-nested-data)

```
use LaravelPlus\Toon\Facades\Toon;

$data = [
    'context' => [
        'task' => 'Our favorite hikes together',
        'location' => 'Boulder',
        'season' => 'spring_2025',
    ],
    'friends' => ['ana', 'luis', 'sam'],
    'hikes' => [
        [
            'id' => 1,
            'name' => 'Blue Lake Trail',
            'distanceKm' => 7.5,
            'elevationGain' => 320,
            'companion' => 'ana',
            'wasSunny' => true,
        ],
        [
            'id' => 2,
            'name' => 'Ridge Overlook',
            'distanceKm' => 9.2,
            'elevationGain' => 540,
            'companion' => 'luis',
            'wasSunny' => false,
        ],
    ],
];

$toon = Toon::encode($data);
```

**Output:**

```
context:
  task: Our favorite hikes together
  location: Boulder
  season: spring_2025
friends[3]: ana,luis,sam
hikes[2]{companion,distanceKm,elevationGain,id,name,wasSunny}:
  1,Blue Lake Trail,7.5,320,ana,true
  2,Ridge Overlook,9.2,540,luis,false

```

#### Using Without Facade

[](#using-without-facade)

```
use LaravelPlus\Toon\ToonManager;

$manager = app(ToonManager::class);
$toon = $manager->encode($data);
```

#### Using Global Helper Function

[](#using-global-helper-function-1)

The `toon()` helper function provides a fluent interface for all TOON operations:

```
// Encode - fluent style
$toon = toon($data)->encode();

// Encode - direct style
$toon = toon()->encode($data);

// Decode - fluent style
$data = toon($toon)->decode();

// Decode - direct style
$data = toon()->decode($toon);

// Database operations
$toon = toon($user)->fromEloquent();
$toon = toon($users)->fromEloquentCollection(['profile']);
$toon = toon($query)->fromQueryBuilder();
$toon = toon($collection)->fromCollection();

// LLM operations
$toon = toon($data)->forLlm();
$data = toon($toon)->fromLlm();
$result = toon($toon)->fromLlmWithValidation();

// Validation
$validation = toon($toon)->validate();

// Format conversion
$json = toon($toon)->toJson();
$toon = toon($json)->fromJson();
$xml = toon($toon)->toXml();
$toon = toon($xml)->fromXml();
$yaml = toon($toon)->toYaml();
$toon = toon($yaml)->fromYaml();
$csv = toon($toon)->toCsv();
$toon = toon($csv)->fromCsv();
$xlsx = toon($toon)->toXlsx();
$toon = toon($xlsx)->fromXlsx();

// Prompt builder
$prompt = toon()->prompt()
    ->system('You are helpful')
    ->user('Analyze this')
    ->withData($data)
    ->build();
```

Architecture
------------

[](#architecture)

This package follows SOLID principles with interfaces and abstractions:

### Interfaces

[](#interfaces)

- **`ToonManagerInterface`** - Main interface for TOON operations
- **`LlmEncoderInterface`** - Interface for LLM-specific encoding
- **`LlmDecoderInterface`** - Interface for LLM response decoding
- **`PromptBuilderInterface`** - Interface for building LLM prompts
- **`DatabaseConverterInterface`** - Interface for database converters

### Abstract Classes

[](#abstract-classes)

- **`AbstractToonConverter`** - Base class for custom TOON converters

### Dependency Injection

[](#dependency-injection)

You can type-hint interfaces in your classes:

```
use LaravelPlus\Toon\Contracts\ToonManagerInterface;

class MyService
{
    public function __construct(
        private ToonManagerInterface $toon
    ) {}

    public function processData(array $data): string
    {
        return $this->toon->encode($data);
    }
}
```

API Reference
-------------

[](#api-reference)

### Facade Methods

[](#facade-methods)

#### `Toon::encode(array $data): string`

[](#toonencodearray-data-string)

Encode an array to TOON format.

#### `Toon::decode(string $toon): array`

[](#toondecodestring-toon-array)

Decode TOON format to an array.

#### `Toon::fromEloquent(Model $model, ?array $relations = null): string`

[](#toonfromeloquentmodel-model-array-relations--null-string)

Convert an Eloquent model to TOON format.

#### `Toon::fromEloquentCollection(EloquentCollection $collection, ?array $relations = null): string`

[](#toonfromeloquentcollectioneloquentcollection-collection-array-relations--null-string)

Convert an Eloquent collection to TOON format.

#### `Toon::fromQueryBuilder(Builder|QueryBuilder $query, ?array $columns = null): string`

[](#toonfromquerybuilderbuilderquerybuilder-query-array-columns--null-string)

Convert Query Builder results to TOON format.

#### `Toon::fromCollection(Collection $collection): string`

[](#toonfromcollectioncollection-collection-string)

Convert a Laravel Collection to TOON format.

#### `Toon::forLlm(array $data): string`

[](#toonforllmarray-data-string)

Encode data specifically for LLM prompts.

#### `Toon::fromLlm(string $toon): array`

[](#toonfromllmstring-toon-array)

Decode LLM response from TOON format.

#### `Toon::fromLlmWithValidation(string $toon): array`

[](#toonfromllmwithvalidationstring-toon-array)

Decode LLM response with validation. Returns `['data' => array, 'valid' => bool, 'errors' => array]`.

#### `Toon::validate(string $toon): array`

[](#toonvalidatestring-toon-array)

Validate a TOON string. Returns `['valid' => bool, 'errors' => array]`.

#### `Toon::prompt(): PromptBuilder`

[](#toonprompt-promptbuilder)

Create a new prompt builder instance.

#### `Toon::toJson(string $toon, int $flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE): string`

[](#toontojsonstring-toon-int-flags--json_pretty_print--json_unescaped_slashes--json_unescaped_unicode-string)

Convert TOON format to JSON.

#### `Toon::fromJson(string $json, int $depth = 512): string`

[](#toonfromjsonstring-json-int-depth--512-string)

Convert JSON to TOON format.

#### `Toon::toXml(string $toon, string $rootElement = 'root', string $version = '1.0', string $encoding = 'UTF-8'): string`

[](#toontoxmlstring-toon-string-rootelement--root-string-version--10-string-encoding--utf-8-string)

Convert TOON format to XML.

#### `Toon::fromXml(string $xml): string`

[](#toonfromxmlstring-xml-string)

Convert XML to TOON format.

#### `Toon::toYaml(string $toon, int $inline = 2, int $indent = 2, int $flags = 0): string`

[](#toontoyamlstring-toon-int-inline--2-int-indent--2-int-flags--0-string)

Convert TOON format to YAML.

#### `Toon::fromYaml(string $yaml, int $flags = 0): string`

[](#toonfromyamlstring-yaml-int-flags--0-string)

Convert YAML to TOON format.

#### `Toon::toCsv(string $toon, string $delimiter = ',', string $enclosure = '"', string $escape = '\\', bool $includeHeaders = true): string`

[](#toontocsvstring-toon-string-delimiter---string-enclosure---string-escape---bool-includeheaders--true-string)

Convert TOON format to CSV.

#### `Toon::fromCsv(string $csv, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): string`

[](#toonfromcsvstring-csv-string-delimiter---string-enclosure---string-escape---string)

Convert CSV to TOON format.

#### `Toon::toXlsx(string $toon, bool $includeHeaders = true, string $sheetName = 'Sheet1'): string`

[](#toontoxlsxstring-toon-bool-includeheaders--true-string-sheetname--sheet1-string)

Convert TOON format to XLSX. Returns base64 encoded XLSX content.

#### `Toon::fromXlsx(string $xlsxPath, ?string $sheetName = null): string`

[](#toonfromxlsxstring-xlsxpath-string-sheetname--null-string)

Convert XLSX file (path or base64 encoded content) to TOON format.

### PromptBuilder Methods

[](#promptbuilder-methods)

#### `system(string $prompt): self`

[](#systemstring-prompt-self)

Set the system prompt.

#### `user(string $prompt): self`

[](#userstring-prompt-self)

Set the user prompt.

#### `withData(array $data): self`

[](#withdataarray-data-self)

Add data to include in TOON format.

#### `withInstructions(bool $include = true): self`

[](#withinstructionsbool-include--true-self)

Include TOON format instructions in the prompt.

#### `build(): string`

[](#build-string)

Build and return the complete prompt.

#### `forAnalysis(string $question, array $data): string`

[](#foranalysisstring-question-array-data-string)

Build a prompt for data analysis.

#### `forTransformation(string $instructions, array $data): string`

[](#fortransformationstring-instructions-array-data-string)

Build a prompt for data transformation.

#### `forExtraction(string $question, array $data): string`

[](#forextractionstring-question-array-data-string)

Build a prompt for data extraction.

Testing
-------

[](#testing)

Run the test suite using Pest:

```
./vendor/bin/pest
```

Or with PHPUnit:

```
./vendor/bin/phpunit
```

Code Quality
------------

[](#code-quality)

This package uses:

- **Pest PHP** for testing
- **Rector** for automated refactoring

Run Rector to analyze and fix code:

```
./vendor/bin/rector process src --dry-run
./vendor/bin/rector process src
```

TOON Format Specification
-------------------------

[](#toon-format-specification)

TOON supports three main formats:

1. **Tabular Arrays**: For uniform arrays of objects

    ```
    users[2]{id,name,role}:
      1,Alice,admin
      2,Bob,user

    ```
2. **Inline Arrays**: For arrays of primitives

    ```
    tags[3]: php,laravel,toon

    ```
3. **Objects**: For nested structures

    ```
    user:
      name: Alice
      profile:
        bio: Developer

    ```

Performance
-----------

[](#performance)

TOON format is optimized for:

- **Token efficiency**: Reduces token count by 50-70% for uniform arrays
- **LLM parsing**: Explicit structure helps models parse reliably
- **Validation**: Built-in array length and field count validation

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Credits
-------

[](#credits)

- TOON format specification: [toonformat.dev](https://toonformat.dev)
- LaravelPlus Team

Support
-------

[](#support)

For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/LaravelPlus/toon).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

168d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e4629de002c40aef796e5b320091892f0b7b35b62497260c52cef3eb721eed1?d=identicon)[Nejcc](/maintainers/Nejcc)

###  Code Quality

TestsPest

Static AnalysisRector

### Embed Badge

![Health badge](/badges/laravelplus-toon/health.svg)

```
[![Health](https://phpackages.com/badges/laravelplus-toon/health.svg)](https://phpackages.com/packages/laravelplus-toon)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M683](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k1](/packages/bjuppa-laravel-blog)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
