定制 azzoelabbar/laravel-toon-export 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

azzoelabbar/laravel-toon-export

Composer 安装命令:

composer require azzoelabbar/laravel-toon-export

包简介

Hashed TOON exporters for Laravel (collections, models, queries).

README 文档

README

Hashed × Laravel

Laravel TOON Export

A Hashed package that exports Laravel data (Eloquent models, queries, collections) into TOON format — optimized for LLM/token usage.

Latest Version Total Downloads License

Think of it as: Export::toJSON / toCSV → now also toTOON

Why TOON?

TOON format is a compact, structured data format perfect for AI/LLM pipelines. It uses significantly fewer tokens than JSON while maintaining structure.

JSON (bloated):

[
  { "id": 1, "name": "Panadol", "price": 3.5 },
  { "id": 2, "name": "Nizoral", "price": 18.9 }
]

TOON (compact):

products[2]{id,name,price}:
1,Panadol,3.5
2,Nizoral,18.9

Result: ~70% fewer tokens, same information.

Installation

Install via Composer:

composer require azzoelabbar/laravel-toon-export

The package will auto-discover and register itself. No configuration needed.

Quick Start

use Hashed\ToonExport\Facades\ToonExport;
use App\Models\User;

// Export from collection
$users = User::select('id', 'name', 'email')->get();
$toon = ToonExport::fromCollection($users, 'users', ['id', 'name', 'email']);

// Export from query
$toon = ToonExport::fromQuery(
    User::query()->where('active', true),
    'active_users',
    ['id', 'name', 'email']
);

// Output:
// users[3]{id,name,email}:
// 1,Azzo,azzo@example.com
// 2,Ali,ali@example.com
// 3,Salah,salah@elabbar.com

Usage

Export from Collection

use Hashed\ToonExport\Facades\ToonExport;

$products = Product::all();
$toon = ToonExport::fromCollection($products, 'products', ['id', 'name', 'price']);

Export from Query Builder

$toon = ToonExport::fromQuery(
    Order::query()
        ->where('status', 'completed')
        ->where('created_at', '>=', now()->subMonth()),
    'recent_orders',
    ['id', 'user_id', 'total', 'created_at']
);

HTTP Download Response

Route::get('/export/users.toon', function () {
    $users = User::select('id', 'name', 'email')->get();
    $toon = ToonExport::fromCollection($users, 'users', ['id', 'name', 'email']);
    
    return response($toon, 200, [
        'Content-Type' => 'text/plain; charset=utf-8',
        'Content-Disposition' => 'attachment; filename="users.toon"',
    ]);
});

Artisan Command

Export models directly from the command line:

# Basic export
php artisan toon:export "App\Models\User" --columns=id,name,email

# Custom name and path
php artisan toon:export "App\Models\Product" \
  --name=products \
  --columns=id,name,price \
  --path=exports

Command Options:

  • model (required): Fully qualified model class, e.g. App\Models\User
  • --name: Root TOON name (defaults to snake_case of model name)
  • --columns: Comma-separated list of columns to export
  • --path: Subdirectory under storage/app (default: toon)

Examples:

# Export with default name
php artisan toon:export "App\Models\Product"
# Creates: storage/app/toon/product.toon

# Export with custom name and columns
php artisan toon:export "App\Models\User" \
  --name=active_users \
  --columns=id,name,email,role

# Export to custom directory
php artisan toon:export "App\Models\Order" \
  --name=recent_orders \
  --path=exports/toon
# Creates: storage/app/exports/toon/recent_orders.toon

Advanced Usage

Multiple Tables

$users = ToonExport::fromCollection($users, 'users', ['id', 'name']);
$orders = ToonExport::fromCollection($orders, 'orders', ['id', 'user_id', 'total']);

$combined = $users . "\n\n" . $orders;

Custom Data Arrays

$data = [
    ['id' => 1, 'name' => 'Item 1', 'price' => 10.5],
    ['id' => 2, 'name' => 'Item 2', 'price' => 20.0],
];

$toon = ToonExport::fromCollection(
    collect($data), 
    'items', 
    ['id', 'name', 'price']
);

AI/LLM Integration

use Hashed\ToonExport\Facades\ToonExport;

// Export data for LLM processing
$users = User::where('city', 'Benghazi')->get();
$toon = ToonExport::fromCollection($users, 'users', ['id', 'name', 'email', 'city']);

// Send to OpenAI/Anthropic
$prompt = "Analyze this user data:\n\n{$toon}\n\nWhat patterns do you see?";
// ... send to LLM API

TOON Format Specification

The TOON format follows this structure:

table_name[record_count]{column1,column2,column3}:
value1,value2,value3
value1,value2,value3
...

Rules:

  • Header: name[count]{columns}:
  • Data rows: comma-separated values, one per line
  • Values with commas/newlines are automatically quoted
  • Empty values are represented as empty strings

Example:

products[3]{id,name,price,stock}:
1,Panadol,3.5,100
2,Nizoral,18.9,50
3,Aspirin,2.0,

Requirements

  • PHP ^8.1
  • Laravel ^10.0 || ^11.0 || ^12.0

Features

  • Export from Eloquent Collections
  • Export from Query Builders
  • Artisan command for CLI exports
  • Auto-discovery (no manual registration)
  • Token-efficient format for AI/LLM
  • Works with any Eloquent model
  • Supports custom columns selection
  • Automatic escaping for special characters

Use Cases

  • AI/LLM Pipelines: Send structured data to OpenAI, Anthropic, etc.
  • Data Exports: Create compact export files
  • API Responses: Return token-efficient data formats
  • Admin Dashboards: Export data for analysis
  • Batch Processing: Prepare data for AI processing

Examples

Controller Example

<?php

namespace App\Http\Controllers;

use Hashed\ToonExport\Facades\ToonExport;
use App\Models\Product;

class ExportController extends Controller
{
    public function products()
    {
        $products = Product::select('id', 'name', 'price', 'stock')->get();
        
        $toon = ToonExport::fromCollection($products, 'products', [
            'id', 'name', 'price', 'stock'
        ]);
        
        return response($toon, 200, [
            'Content-Type' => 'text/plain; charset=utf-8',
            'Content-Disposition' => 'attachment; filename="products.toon"',
        ]);
    }
}

Service Example

<?php

namespace App\Services;

use Hashed\ToonExport\Facades\ToonExport;
use App\Models\User;

class AIDataService
{
    public function prepareUserDataForLLM(array $userIds): string
    {
        $users = User::whereIn('id', $userIds)
            ->select('id', 'name', 'email', 'created_at')
            ->get();
        
        return ToonExport::fromCollection($users, 'users', [
            'id', 'name', 'email', 'created_at'
        ]);
    }
}

Testing

Test the package with:

# Test Artisan command
php artisan toon:export "App\Models\User" --columns=id,name,email

# Test in Tinker
php artisan tinker

Then:

use Hashed\ToonExport\Facades\ToonExport;
use App\Models\User;

$users = User::limit(3)->get();
echo ToonExport::fromCollection($users, 'users', ['id', 'name', 'email']);

Documentation

Troubleshooting

Command not found?

php artisan package:discover
composer dump-autoload

Class not found?

composer dump-autoload
php artisan config:clear

License

The MIT License (MIT). Please see License File for more information.

Credits

Built by Hashed for the Laravel community, optimized for AI/LLM workflows.

azzoelabbar/laravel-toon-export 适用场景与选型建议

azzoelabbar/laravel-toon-export 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「export」 「laravel」 「eloquent」 「ai」 「llm」 「toon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 azzoelabbar/laravel-toon-export 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 azzoelabbar/laravel-toon-export 我们能提供哪些服务?
定制开发 / 二次开发

基于 azzoelabbar/laravel-toon-export 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-15