0

Laravel Excel export relation columns give array and Arabic words is become like \u0633\u0627\u0645\u0633\u0648\u0646\u062c how to solve it ? I tried to use json_encode($subcategory->name, JSON_UNESCAPED_UNICODE) and it is not working also and give same results. Does anyone have some suggestions to solve this?

Export file

class CategoriesExport implements FromQuery, WithMapping, WithHeadings
{
    use Exportable;

    protected $checked;

    public function __construct($checked)
    {
        $this->checked = $checked;
    }

    public function map($category): array
    {
         return [
            $category->id,
            $category->name,
            $category->status == 1 ? trans('applang.active') : trans('applang.suspended'),
            $category->section->name,
            $category->brands->map(function ($brand){ return $brand->name; }),
            $category->subCategories->map(function ($subcategory){ return $subcategory->name; })
        ];
    }

    public function headings(): array
    {
        return [
            '#ID',
            trans('applang.the_category'),
            trans('applang.status'),
            trans('applang.the_section'),
            trans('applang.the_brand'),
            trans('applang.sub_cat'),
        ];
    }

    public function query()
    {
        return Category::with(['section', 'brands', 'subCategories', 'products'])->whereIn('id', $this->checked);
    }
}
Karl Hill
  • 9,745
  • 4
  • 52
  • 77

1 Answers1

0

In your config/excel.php change the use_bom config to true and try with that.

from What's the difference between UTF-8 and UTF-8 without BOM?

The UTF-8 BOM is a sequence of bytes at the start of a text stream (0xEF, 0xBB, 0xBF) that allows the reader to more reliably guess a file as being encoded in UTF-8.

Mohsen Nazari
  • 1,131
  • 1
  • 1
  • 12