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