source: app/Exports/UsersExport.php@ fb32aad

develop
Last change on this file since fb32aad 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
RevLine 
[c6b84df]1<?php
2
3namespace App\Exports;
4
5use App\Models\Role;
6use App\Models\User;
7use Maatwebsite\Excel\Concerns\FromCollection;
8use Maatwebsite\Excel\Concerns\WithHeadings;
9use Maatwebsite\Excel\Concerns\WithMapping;
10
11class 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,
[4b7e2d3]30 $row->role_id . ' - ' . Role::find($row->role_id)->name,
[c6b84df]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',
[4b7e2d3]48 'Role ID - Username',
[c6b84df]49 'Created by',
50 'Created at',
51 'Updated at'
52 ];
53 }
54}
Note: See TracBrowser for help on using the repository browser.