Skip to content

Column Adjusters

Adjusters transform a column's resolved value before it reaches the frontend. They run after the value is extracted from the model (via data_get or a custom ->value() resolver), so they operate on the result, not on the model itself.

Adjusters are defined on the base Column class, so every column type supports them - TextColumn, EnumColumn, BooleanColumn, and all others.

Built-in Adjusters

uppercase

Converts the value to uppercase using PHP's strtoupper.

php
Column::make('name', 'Name')->text()->uppercase()
// "john doe" -> "JOHN DOE"

lowercase

Converts the value to lowercase using PHP's strtolower.

php
Column::make('email', 'Email')->text()->lowercase()
// "John@Example.COM" -> "john@example.com"

ucFirst

Capitalizes the first character of the value using PHP's ucfirst.

php
Column::make('name', 'Name')->text()->ucFirst()
// "hello world" -> "Hello world"

ucWords

Capitalizes the first character of each word using PHP's ucwords.

php
Column::make('name', 'Name')->text()->ucWords()
// "hello world" -> "Hello World"

Custom Adjusters

Use ->adjust() to apply any transformation. The closure receives the resolved value and returns the transformed value:

php
Column::make('price', 'Price')
    ->text()
    ->adjust(fn ($value) => number_format($value, 2))
// 1234.5 -> "1,234.50"

Column::make('description', 'Description')
    ->text()
    ->adjust(fn ($value) => str($value)->limit(50)->toString())
// "Very long description..." -> "Very long description..."

fallback

Replaces null values with a default. Defaults to 'N/A' when called without arguments:

php
Column::make('nickname', 'Nickname')->text()->fallback()
// null -> "N/A"

Column::make('nickname', 'Nickname')->text()->fallback('Unknown')
// null -> "Unknown"

Non-null values pass through unchanged. Chain fallback() before other adjusters to ensure they always receive a string:

php
Column::make('nickname', 'Nickname')->text()->fallback('unknown')->uppercase()
// null -> "unknown" -> "UNKNOWN"

The other built-in adjusters (uppercase, lowercase, ucFirst, ucWords) pass null through unchanged since they only operate on strings.

Chaining

Multiple adjusters are applied left-to-right in the order they are chained:

php
Column::make('name', 'Name')
    ->text()
    ->adjust(fn ($value) => trim($value))
    ->ucWords()
// "  hello world  " -> "Hello World"

Works With All Column Types

Adjusters compose with any column type's value resolver. They always run after the value is resolved:

php
// EnumColumn: getText() resolves first, then uppercase applies
EnumColumn::make('status', 'Status')->uppercase()
// Running -> RUNNING

// BooleanColumn: Yes/No resolves first, then lowercase applies
BooleanColumn::make('active', 'Active')->lowercase()
// Yes -> yes, No -> no

// With a custom value() resolver
Column::make('full_name', 'Name')
    ->value(fn ($model) => $model->first_name . ' ' . $model->last_name)
    ->ucWords()
    ->text()
// john doe -> John Doe

Non-String Values

The built-in adjusters only transform strings. If the column value is not a string (e.g. an integer), the value passes through unchanged. Custom adjust() closures receive whatever type the value is:

php
// Built-in: integer passes through unchanged
Column::make('count', 'Count')->uppercase()
// 42 -> 42 (no change)

// Custom: you control the types
Column::make('count', 'Count')->adjust(fn ($value) => $value * 100)
// 42 -> 4200