EventsService::deleteBanner()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Innoflash\Events\Services;
4
5
use FaithGen\SDK\Traits\FileTraits;
6
use Innoflash\Events\Models\Event;
7
use InnoFlash\LaraStart\Services\CRUDServices;
8
9
class EventsService extends CRUDServices
10
{
11
    use FileTraits;
12
13
    protected Event $event;
14
15
    public function __construct()
16
    {
17
        $this->event = app(Event::class);
18
19
        $eventId = request()->route('event') ?? request('event_id');
20
21
        if ($eventId) {
22
            $this->event = $this->event->resolveRouteBinding($eventId);
23
        }
24
    }
25
26
    /**
27
     * Retrieves an instance of event.
28
     *
29
     * @return \Innoflash\Events\Models\Event
30
     */
31
    public function getEvent(): Event
32
    {
33
        return $this->event;
34
    }
35
36
    /**
37
     * Makes a list of fields that you do not want to be sent
38
     * to the create or update methods.
39
     * Its mainly the fields that you do not have in the messages table.
40
     *
41
     * @return array
42
     */
43
    public function getUnsetFields(): array
44
    {
45
        return ['event_id', 'banner'];
46
    }
47
48
    /**
49
     * Attaches a parent to the current event
50
     * You can delete this if you do not intent to create events from parent relationships.
51
     */
52
    public function getParentRelationship()
53
    {
54
        return auth()->user()->events();
55
    }
56
57
    public function deleteBanner($event)
58
    {
59
        if ($event->image()->exists()) {
60
            $this->deleteFiles($event);
61
            $event->image()->delete();
62
63
            return $this->successResponse('Banner deleted');
64
        }
65
66
        return $this->successResponse('This event doesn`t have a banner already');
67
    }
68
}
69