1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Exports;
- use App\Models\CustomField;
- use App\Models\Enums\CustomFieldType;
- use App\Models\NamingRule;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- class NameRuleExport implements FromCollection, WithHeadings
- {
- public function collection()
- {
- $objects = collect([]);
- $customFields=CustomField::query()->where('group',request()->group)->get();
- foreach ($customFields as $customField){
- $key=$customField['key'];
- $options=$customField->options;
- $inputs=$customField->inputs;
- $type=CustomFieldType::from($customField->type)->name;
- if($customField->type==3){
- foreach ($options as $option){
- $customKey=$option['lang']['en'];
- $customValue=$option['value'];
- $objects->push($this->formatRow($key,$type,$customKey,$customValue));
- }
- }
- if($customField->type==1){
- foreach ($inputs as $input){
- $customKey=$input['lang']['en'];
- $customValue=$input['value'];
- $objects->push($this->formatRow($key,$type,$customKey,$customValue));
- }
- }
- $objects->push($this->formatRow('','','',''));
- }
- return $objects;
- // TODO: Implement collection() method.
- }
- protected function formatRow($key,$type,$customKey,$customValue)
- {
- return [
- $key,
- $type,
- $customKey,
- $customValue,
- ];
- }
- public function headings(): array
- {
- return [
- 'key',
- 'type',
- 'customKey',
- 'customValue',
- ];
- }
- }
|