File size: 1,355 Bytes
89a1081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace App\Exports;

use App\Models\Contact;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Maatwebsite\Excel\Concerns\WithColumnWidths;

class ContactExport implements FromView, WithColumnWidths, WithStyles
{

    protected $status;
    protected $groupId;

    public function __construct($status, $groupId =null) {
        $this->status = $status;
        $this->groupId = $groupId;
    }

    public function view(): View
    {
        if($this->status && !$this->groupId){
            $contacts = Contact::whereNull('user_id')->select('name','contact_no')->get();
        }else if(!$this->status && $this->groupId){
            $contacts = Contact::where('group_id', $this->groupId)->select('name','contact_no')->get();
        }else{
            $contacts = Contact::where('user_id', auth()->user()->id)->select('name','contact_no')->get();
        }
        return view('partials.contact_excel', [
            'contacts' => $contacts,
        ]);
    }


    public function styles(Worksheet $sheet)
    {
    	return [
            'A1' => ['font' => ['bold' => true,'size' => 12,]]
        ];
    }

    public function columnWidths(): array
    {
        return [
            'A' => 30
        ];
    }



}