Skip to main content

Dynamic Usage

The transformation engine is designed to be fully serializable, making it easy to build a GUI on top of it. You can save the transformation configuration as a JSON object in the database and execute it later without writing any PHP code.

Example JSON Configuration: This JSON corresponds to a transformation that lowercases a reference code and calculates a total.

{
"selects": {
"ref": {
"type": "string_function",
"function": "LOWER",
"column": {
"type": "column",
"column": "order_ref"
},
"arguments": []
},
"total": {
"type": "math",
"operator": "+",
"left": {
"type": "column",
"column": "subtotal"
},
"right": {
"type": "column",
"column": "tax"
}
},
"is_paid": {
"type": "map",
"column": "status",
"mapping": { "paid": 1 },
"default": 0
}
}
}

Executing the Saved Transformation:

use Andach\ExtractAndTransform\Models\Transformation;
use Andach\ExtractAndTransform\Services\TransformationService;

// 1. Load the transformation model (which contains the JSON config)
$transformation = Transformation::where('name', 'My Saved Transform')->first();

// 2. Run it
app(TransformationService::class)->run($transformation);

The service automatically rehydrates the JSON configuration into executable expressions.