TestimonialRepository   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A storeTestimonial() 0 4 1
A createTestimonial() 0 2 1
A showTestimonial() 0 3 1
A editTestimonial() 0 3 1
A updateTestimonial() 0 4 1
A indexTestimonial() 0 9 3
A uploadImage() 0 6 2
A destroyTestimonial() 0 3 1
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\TestimonialRepositoryInterface;
6
use Adminetic\Website\Http\Requests\TestimonialRequest;
7
use Adminetic\Website\Models\Admin\Testimonial;
8
use Illuminate\Support\Facades\Cache;
9
10
class TestimonialRepository implements TestimonialRepositoryInterface
11
{
12
    // Testimonial Index
13
    public function indexTestimonial()
14
    {
15
        $testimonials = config('adminetic.caching', true)
16
            ? (Cache::has('testimonials') ? Cache::get('testimonials') : Cache::rememberForever('testimonials', function () {
17
                return Testimonial::orderBy('position')->get();
18
            }))
19
            : Testimonial::orderBy('position')->get();
20
21
        return compact('testimonials');
22
    }
23
24
    // Testimonial Create
25
    public function createTestimonial()
26
    {
27
        //
28
    }
29
30
    // Testimonial Store
31
    public function storeTestimonial(TestimonialRequest $request)
32
    {
33
        $testimonial = Testimonial::create($request->validated());
34
        $this->uploadImage($testimonial);
35
    }
36
37
    // Testimonial Show
38
    public function showTestimonial(Testimonial $testimonial)
39
    {
40
        return compact('testimonial');
41
    }
42
43
    // Testimonial Edit
44
    public function editTestimonial(Testimonial $testimonial)
45
    {
46
        return compact('testimonial');
47
    }
48
49
    // Testimonial Update
50
    public function updateTestimonial(TestimonialRequest $request, Testimonial $testimonial)
51
    {
52
        $testimonial->update($request->validated());
53
        $this->uploadImage($testimonial);
54
    }
55
56
    // Testimonial Destroy
57
    public function destroyTestimonial(Testimonial $testimonial)
58
    {
59
        $testimonial->delete();
60
    }
61
62
    // Upload Image
63
    private function uploadImage(Testimonial $testimonial)
64
    {
65
        if (request()->has('image')) {
66
            $testimonial
67
                ->addFromMediaLibraryRequest(request()->image)
68
                ->toMediaCollection('image');
69
        }
70
    }
71
}
72