Passed
Push — main ( bb1631...b48e8d )
by PRATIK
07:52 queued 04:02
created

HistoryRepository   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 60
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createHistory() 0 2 1
A editHistory() 0 3 1
A destroyHistory() 0 3 1
A uploadImage() 0 6 2
A showHistory() 0 3 1
A updateHistory() 0 4 1
A storeHistory() 0 4 1
A indexHistory() 0 8 3
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