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