Chaining Transformations
You can chain multiple operations together to build complex logic.
ExtractAndTransform::transform('Advanced Transform')
->from('raw_products')
->select([
// Chain math: (price * 1.2) + 5
'final_price' => Expr::col('price')
->multiply(1.2)
->add(5),
// Chain string functions: LOWER(REPLACE(name, ' ', '-'))
'slug' => Expr::col('name')
->replace(' ', '-')
->lower(),
// Combine concatenation and string functions
'report_name' => Expr::concat(Expr::col('brand'), ': ', Expr::col('name'))->upper(),
])
->toTable('advanced_products')
->run();
Available Expressions
Expr::col(string $column): Selects a column.Expr::concat(...$parts): Concatenates columns and strings.Expr::map(string $column, array $mapping): Creates aCASE WHENstatement.Expr::lookup(string $table, string $localKey, string $foreignKey, string $targetColumn): Performs aLEFT JOINto fetch a value from another table.
Chainable Methods
- Numeric:
add(),subtract(),multiply(),divide() - String:
upper(),lower(),trim(),replace($search, $replace)