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
|
|
|
|