Available Transformations
All expressions are created using the Andach\ExtractAndTransform\Transform\Expr factory class.
Column Selection
The col() function simply selects a column and does nothing more.
use Andach\ExtractAndTransform\Transform\Expr;
// Select the 'price' column
Expr::col('price')
Concatenation
The concatenation function accepts a number of strings. These could be literals, or results of the Expr::col() function call.
// Result: "John Smith"
Expr::concat(Expr::col('first_name'), ' ', Expr::col('last_name'))
// Result: "ID: 123"
Expr::concat('ID: ', Expr::col('id'))
Static Mapping (Case Statement)
These are discussed in more detail in the mapping documentation section.
Lookups (Left Joins)
These are discussed in more detail in the lookups documentation section.
Chainable Methods
Expressions can be modified by chaining methods.
Numeric Operations
These methods can be chained onto any expression that resolves to a number.
- add(mixed $value): Adds a value or column.
- subtract(mixed $value): Subtracts a value or column.
- multiply(mixed $value): Multiplies by a value or column.
- divide(mixed $value): Divides by a value or column.
// Calculate tax: price * 0.2
Expr::col('price')->multiply(0.2)
// Calculate total: (subtotal + tax) - discount
Expr::col('subtotal')
->add(Expr::col('tax'))
->subtract(Expr::col('discount'))
String Functions
These methods can be chained onto any expression that resolves to a string.
- upper(): Converts string to uppercase.
- lower(): Converts string to lowercase.
- trim(): Removes whitespace from both ends.
- replace(string $search, string $replace): Replaces all occurrences of a search string.
For example:
// Normalize email: LOWER(TRIM(email))
Expr::col('email')->trim()->lower();
// Create slug: LOWER(REPLACE(name, ' ', '-'))
Expr::col('name')->replace(' ', '-')->lower();