|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use Adminetic\Website\Contracts\CounterRepositoryInterface; |
|
6
|
|
|
use Adminetic\Website\Http\Requests\CounterRequest; |
|
7
|
|
|
use Adminetic\Website\Models\Admin\Counter; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
|
|
10
|
|
|
class CounterRepository implements CounterRepositoryInterface |
|
11
|
|
|
{ |
|
12
|
|
|
// Counter Index |
|
13
|
|
|
public function indexCounter() |
|
14
|
|
|
{ |
|
15
|
|
|
$counters = config('adminetic.caching', true) |
|
16
|
|
|
? (Cache::has('counters') ? Cache::get('counters') : Cache::rememberForever('counters', function () { |
|
17
|
|
|
return Counter::orderBy('position')->get(); |
|
18
|
|
|
})) |
|
19
|
|
|
: Counter::orderBy('position')->get(); |
|
20
|
|
|
|
|
21
|
|
|
return compact('counters'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
// Counter Create |
|
25
|
|
|
public function createCounter() |
|
26
|
|
|
{ |
|
27
|
|
|
// |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// Counter Store |
|
31
|
|
|
public function storeCounter(CounterRequest $request) |
|
32
|
|
|
{ |
|
33
|
|
|
$counter = Counter::create($request->validated()); |
|
34
|
|
|
$this->uploadImage($counter); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Counter Show |
|
38
|
|
|
public function showCounter(Counter $counter) |
|
39
|
|
|
{ |
|
40
|
|
|
return compact('counter'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Counter Edit |
|
44
|
|
|
public function editCounter(Counter $counter) |
|
45
|
|
|
{ |
|
46
|
|
|
return compact('counter'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Counter Update |
|
50
|
|
|
public function updateCounter(CounterRequest $request, Counter $counter) |
|
51
|
|
|
{ |
|
52
|
|
|
$counter->update($request->validated()); |
|
53
|
|
|
$this->uploadImage($counter); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// Counter Destroy |
|
57
|
|
|
public function destroyCounter(Counter $counter) |
|
58
|
|
|
{ |
|
59
|
|
|
$counter->delete(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Upload Image |
|
63
|
|
|
private function uploadImage(Counter $counter) |
|
64
|
|
|
{ |
|
65
|
|
|
if (request()->has('icon_image')) { |
|
66
|
|
|
$counter |
|
67
|
|
|
->addFromMediaLibraryRequest(request()->icon_image) |
|
68
|
|
|
->toMediaCollection('icon_image'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|