File: /mnt/data/ghayatcom/ghayatcom-api/app/Exports/LanguageFileExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class LanguageFileExport implements FromCollection, WithHeadings
{
protected $translations;
public function __construct(array $translations)
{
$this->translations = $translations;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
$data = [];
foreach ($this->translations as $index => $module) {
foreach ($module as $key => $value) {
$data[] = [
'module' => $index,
'key' => $key,
'english' => $value,
'translation' => ''
];
}
}
return collect($data);
}
public function headings(): array
{
return [
'Module',
'Key',
'English',
'Translation'
];
}
}