source: app/Exports/DepartmentsExport.php@ e2e83fc

develop
Last change on this file since e2e83fc was 4b7e2d3, checked in by beratkjufliju <kufliju@…>, 3 years ago

bug fixes, edited export, added fileSeeder for DB testing

  • Property mode set to 100644
File size: 1.0 KB
Line 
1<?php
2
3namespace App\Exports;
4
5use App\Models\Department;
6use App\Models\User;
7use Maatwebsite\Excel\Concerns\FromCollection;
8use Maatwebsite\Excel\Concerns\WithHeadings;
9use Maatwebsite\Excel\Concerns\WithMapping;
10
11class DepartmentsExport implements FromCollection, WithMapping, WithHeadings
12{
13 /**
14 * @return \Illuminate\Support\Collection
15 */
16 public function collection()
17 {
18 return Department::all();
19 }
20
21 public function map($row): array{
22 $fields = [
23 $row->id,
24 $row->name,
25 $row->code,
26 $row->no_of_folders,
27 $row->user_id . ' - ' . User::find($row->user_id)->username,
28 $row->created_at,
29 $row->updated_at
30 ];
31 return $fields;
32 }
33
34 public function headings(): array
35 {
36 return [
37 'ID',
38 'Name',
39 'Code',
40 'Number of folders',
41 'Created by ID - Username',
42 'Created at',
43 'Updated at',
44 ];
45 }
46}
Note: See TracBrowser for help on using the repository browser.