Passed
Push — main ( 86a6dd...ec1f24 )
by PRATIK
03:12
created

EventRepository::storeEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Illuminate\Support\Facades\Cache;
6
use Adminetic\Website\Models\Admin\Event;
7
use Adminetic\Website\Models\Admin\Gallery;
8
use Adminetic\Website\Http\Requests\EventRequest;
9
use Adminetic\Website\Contracts\EventRepositoryInterface;
10
11
class EventRepository implements EventRepositoryInterface
12
{
13
    // Event Index
14
    public function indexEvent()
15
    {
16
        $events = config('adminetic.caching', true)
17
            ? (Cache::has('events') ? Cache::get('events') : Cache::rememberForever('events', function () {
18
                return Event::latest()->get();
19
            }))
20
            : Event::latest()->get();
21
        return compact('events');
22
    }
23
24
    // Event Create
25
    public function createEvent()
26
    {
27
        $galleries = Cache::get('galleries', Gallery::latest()->get());
28
        return compact('galleries');
29
    }
30
31
    // Event Store
32
    public function storeEvent(EventRequest $request)
33
    {
34
        $event = Event::create($request->validated());
35
        $this->uploadImage($event);
36
    }
37
38
    // Event Show
39
    public function showEvent(Event $event)
40
    {
41
        return compact('event');
42
    }
43
44
    // Event Edit
45
    public function editEvent(Event $event)
46
    {
47
        $galleries = Cache::get('galleries', Gallery::latest()->get());
48
        return compact('event', 'galleries');
49
    }
50
51
    // Event Update
52
    public function updateEvent(EventRequest $request, Event $event)
53
    {
54
        $event->update($request->validated());
55
        $this->uploadImage($event);
56
    }
57
58
    // Event Destroy
59
    public function destroyEvent(Event $event)
60
    {
61
        $event->delete();
62
    }
63
64
    // Upload Image
65
    protected function uploadImage(Event $event)
66
    {
67
        if (request()->image) {
68
            $thumbnails = [
69
                'storage' => 'website/event/' . validImageFolder($event->id, 'event'),
0 ignored issues
show
Bug introduced by
The function validImageFolder was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
                'storage' => 'website/event/' . /** @scrutinizer ignore-call */ validImageFolder($event->id, 'event'),
Loading history...
70
                'width' => '1200',
71
                'height' => '630',
72
                'quality' => '100',
73
                'thumbnails' => [
74
                    [
75
                        'thumbnail-name' => 'medium',
76
                        'thumbnail-width' => '730',
77
                        'thumbnail-height' => '500',
78
                        'thumbnail-quality' => '90'
79
                    ],
80
                    [
81
                        'thumbnail-name' => 'small',
82
                        'thumbnail-width' => '80',
83
                        'thumbnail-height' => '70',
84
                        'thumbnail-quality' => '70'
85
                    ]
86
                ]
87
            ];
88
            $event->makeThumbnail('image', $thumbnails);
89
        }
90
    }
91
}
92