develop
Last change
on this file since b39afb5 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.2 KB
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Exports;
|
---|
4 |
|
---|
5 | use App\Models\Role;
|
---|
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 UsersExport implements FromCollection, WithMapping, WithHeadings
|
---|
12 | {
|
---|
13 | /**
|
---|
14 | * @return \Illuminate\Support\Collection
|
---|
15 | */
|
---|
16 | public function collection()
|
---|
17 | {
|
---|
18 | return User::all();
|
---|
19 | }
|
---|
20 |
|
---|
21 | public function map($row): array{
|
---|
22 | $fields = [
|
---|
23 | $row->id,
|
---|
24 | $row->name,
|
---|
25 | $row->surname,
|
---|
26 | $row->username,
|
---|
27 | $row->email,
|
---|
28 | $row->phone_number,
|
---|
29 | $row->is_confirmed,
|
---|
30 | $row->role_id . ' - ' . Role::find($row->role_id)->name,
|
---|
31 | $row->where('id', $row->created_by)->pluck('username')->first(),
|
---|
32 | $row->created_at,
|
---|
33 | $row->updated_at
|
---|
34 | ];
|
---|
35 | return $fields;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public function headings(): array
|
---|
39 | {
|
---|
40 | return [
|
---|
41 | 'ID',
|
---|
42 | 'Name',
|
---|
43 | 'Surname',
|
---|
44 | 'Username',
|
---|
45 | 'Email',
|
---|
46 | 'Phone number',
|
---|
47 | 'Is confirmed',
|
---|
48 | 'Role ID - Username',
|
---|
49 | 'Created by',
|
---|
50 | 'Created at',
|
---|
51 | 'Updated at'
|
---|
52 | ];
|
---|
53 | }
|
---|
54 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.