mapColumn(string $mappedColumnName, string $originalColumnName)

Map a column field with another. Use the same column field for multiple columns. Useful to combine it with callbackColumn.

Syntax example:

$crud->mapColumn('customer_name', 'full_name');

The most common usage is with callbackColumn when a field doesn't exist in the database.


$crud->setSubject('Customer', 'Customers');

$crud->columns(['full_name','phone','addressLine1','creditLimit', 'contactFirstName']);

// Make sure that you have a field type or else
// mapColumn will not work with callbackColumn
$crud->fieldTypeColumn('full_name', 'varchar');

// We would like to hide contactFirstName just to use it into the callbackColumn
$crud->fieldTypeColumn('contactFirstName', 'invisible');

$crud->mapColumn('full_name', 'contactLastName');
$crud->callbackColumn('full_name', function ($value, $row) {
    // the $value in our case is contactLastName
    return $value . ' ' . $row->contactFirstName;

$output = $crud->render();