Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Create or merge fields when exporting a model

0
by AIC BV, last modified on March 20th, 2023

Hi,

If you want to merge fields on export you can do the following:

  1. Change your models/ModelExport.php

    
    class YourmodelExport extends ExportModel
    {
    
    public $table = 'your_table';
    
    protected $appends = [
        'full_name'
    ];
    
    public function exportData($columns, $sessionKey = null)
    {
        $result = self::make()
            ->get()
            ->toArray();
    
        return $result;
    }
    
    public function getFullNameAttribute()
    {
        return $this->firstname . ' ' . $this->lastname;
    }

}


2. Add the fields to your models/yourmodelexport/columns.yaml

columns: ... full_name: Full name

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?