-
Notifications
You must be signed in to change notification settings - Fork 2
/
ManageLogo.php
100 lines (85 loc) · 2.31 KB
/
ManageLogo.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace App\Livewire\Company;
use App\Traits\FileValidation;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Livewire\WithFileUploads;
class ManageLogo extends Component
{
use WithFileUploads;
use FileValidation;
public $photo;
public $currentLogo;
public $company;
public $theme;
/**
* Triggered when initializing the component
* @param $company
* @return void
*/
public function mount($company, $theme = 'light')
{
$this->company = $company;
$this->theme = $theme;
$this->updateLogoInComponent();
}
/**
* Fetches the path of the saved logo from the database
* @return void
*/
public function updateLogoInComponent()
{
$this->currentLogo = $this->theme == 'light' ?
$this->company->logo_path :
$this->company->dark_logo_path;
}
/**
* Renders the component
*/
public function updatedPhoto()
{
$this->validateFileNameLength($this->photo, 'photo');
$this->validate([
'photo' => [
'image',
'max:10240',
]
], [
'file.max' => 'The file must not be larger than 10MB',
]);
}
/**
* Saves the photo uploaded by the company
* @return void
*/
public function save()
{
$this->validateFileNameLength($this->photo, 'photo');
$this->validate([
'photo' => [
'image',
'max:10240',
]
], [
'file.max' => 'The file must not be larger than 10MB',
]);
$path = $this->photo->store('logos', 'public');
$path_to_be_updated = $this->theme == 'light' ? 'logo_path' : 'dark_logo_path';
$this->company->update([$path_to_be_updated => $path]);
$this->updateLogoInComponent();
//ImageOptimizer::optimize('storage/' . $path);
$this->reset(['photo']);
session()->flash('message', 'Logo successfully updated.');
}
/**
* Renders the component
* @return View
*/
public function render(): View
{
return view('livewire.company.manage-logo');
}
}