develop
Last change
on this file since 4b7e2d3 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 |
|
---|
3 | namespace App\Exports;
|
---|
4 |
|
---|
5 | use App\Models\Department;
|
---|
6 | use App\Models\User;
|
---|
7 | use Maatwebsite\Excel\Concerns\FromCollection;
|
---|
8 | use Maatwebsite\Excel\Concerns\WithHeadings;
|
---|
9 | use Maatwebsite\Excel\Concerns\WithMapping;
|
---|
10 |
|
---|
11 | class 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.