AddOrganizer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 82
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A close() 0 3 1
A handleFileUpload() 0 3 1
A mount() 0 4 1
A render() 0 3 1
A openModal() 0 3 1
A saveOrganizer() 0 16 1
1
<?php
2
3
namespace App\Http\Livewire;
4
5
use App\Helpers\ImageHelpers;
6
use App\Models\Organizer;
7
use App\Repositories\OrganizerRepository;
8
use Illuminate\Http\File;
9
use Illuminate\Http\UploadedFile;
10
use Illuminate\Support\Collection;
11
use Illuminate\Support\Facades\App;
12
use Illuminate\Support\Str;
13
use Livewire\Component;
14
15
class AddOrganizer extends Component
16
{
17
    public $organizers;
18
    public $selected;
19
    public $showModal = false;
20
    public $newOrganizer;
21
    public $profilePicture;
22
23
    protected $rules = [
24
        'newOrganizer.name' => ['required', 'string', 'max:255'],
25
        'newOrganizer.surname' => ['required', 'string', 'max:255'],
26
        'newOrganizer.email' => ['required', 'email', 'max:255'],
27
        'newOrganizer.phone' => ['nullable', 'string', 'max:255'],
28
        'newOrganizer.website' => ['nullable', 'url'],
29
        'newOrganizer.description' => ['required', 'string'],
30
        'profilePicture' => ['nullable'], // 5MB Max - , 'image','mimes:jpg,jpeg,png','max:5120'
31
    ];
32
33
    protected $listeners = [
34
        'fileUpload' => 'handleFileUpload',
35
    ];
36
37
    public function handleFileUpload($imageData)
38
    {
39
        $this->profilePicture = $imageData;
40
    }
41
42
    /**
43
     * The component constructor
44
     *
45
     * @param \Illuminate\Support\Collection $organizers
46
     * @param array|null $selected
47
     */
48
    public function mount(Collection $organizers, ?array $selected)
49
    {
50
        $this->organizers = $organizers;
51
        $this->selected = $selected;
52
    }
53
54
    /**
55
     * Default component render method
56
     */
57
    public function render()
58
    {
59
        return view('livewire.add-organizer');
60
    }
61
62
    /**
63
     * Open the modal
64
     */
65
    public function openModal(): void
66
    {
67
        $this->showModal = true;
68
    }
69
70
    /**
71
     * Close the modal
72
     */
73
    public function close(): void
74
    {
75
        $this->showModal = false;
76
    }
77
78
    /**
79
     * Store a newly created organizer in storage.
80
     */
81
    public function saveOrganizer(): void
82
    {
83
        $organizerRepository = App::make(OrganizerRepository::class);
84
85
        $this->validate();
86
87
        $organizer = $organizerRepository->store($this->newOrganizer);
88
        ImageHelpers::storeImageFromLivewireComponent($organizer, $this->profilePicture, 'profile_picture');
89
90
        $this->selected[] = $organizer->id;
91
        $this->organizers = $organizerRepository->getAll();
92
93
        $this->emit('refreshOrganizersDropdown', ['organizer' => $organizer]);
94
        $this->showModal = false;
95
96
        $this->newOrganizer = [];
97
    }
98
}
99