1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Bookings\Models; |
6
|
|
|
|
7
|
|
|
use Spatie\Sluggable\SlugOptions; |
8
|
|
|
use Rinvex\Support\Traits\HasSlug; |
9
|
|
|
use Illuminate\Database\Eloquent\Model; |
10
|
|
|
use Rinvex\Cacheable\CacheableEloquent; |
11
|
|
|
use Illuminate\Database\Eloquent\Builder; |
12
|
|
|
use Rinvex\Support\Traits\HasTranslations; |
13
|
|
|
use Rinvex\Support\Traits\ValidatingTrait; |
14
|
|
|
use Rinvex\Bookings\Traits\Ticketable as TicketableTrait; |
15
|
|
|
|
16
|
|
|
abstract class Ticketable extends Model |
17
|
|
|
{ |
18
|
|
|
use HasSlug; |
19
|
|
|
use TicketableTrait; |
20
|
|
|
use HasTranslations; |
21
|
|
|
use ValidatingTrait; |
22
|
|
|
use CacheableEloquent; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected $fillable = [ |
28
|
|
|
'slug', |
29
|
|
|
'name', |
30
|
|
|
'description', |
31
|
|
|
'is_public', |
32
|
|
|
'starts_at', |
33
|
|
|
'ends_at', |
34
|
|
|
'timezone', |
35
|
|
|
'location', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
protected $casts = [ |
42
|
|
|
'slug' => 'string', |
43
|
|
|
'name' => 'string', |
44
|
|
|
'description' => 'string', |
45
|
|
|
'is_public' => 'boolean', |
46
|
|
|
'starts_at' => 'datetime', |
47
|
|
|
'ends_at' => 'datetime', |
48
|
|
|
'timezone' => 'string', |
49
|
|
|
'location' => 'string', |
50
|
|
|
'deleted_at' => 'datetime', |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
protected $observables = [ |
57
|
|
|
'validating', |
58
|
|
|
'validated', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public $translatable = [ |
65
|
|
|
'name', |
66
|
|
|
'description', |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The default rules that the model will validate against. |
71
|
|
|
* |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
protected $rules = [ |
75
|
|
|
'slug' => 'required|alpha_dash|max:150', |
76
|
|
|
'name' => 'required|string|max:150', |
77
|
|
|
'description' => 'nullable|string|max:10000', |
78
|
|
|
'is_public' => 'sometimes|boolean', |
79
|
|
|
'starts_at' => 'required|string', |
80
|
|
|
'ends_at' => 'required|string', |
81
|
|
|
'timezone' => 'required|string|timezone', |
82
|
|
|
'location' => 'nullable|string', |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Whether the model should throw a |
87
|
|
|
* ValidationException if it fails validation. |
88
|
|
|
* |
89
|
|
|
* @var bool |
90
|
|
|
*/ |
91
|
|
|
protected $throwValidationExceptions = true; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the public resources. |
95
|
|
|
* |
96
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
97
|
|
|
* |
98
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
99
|
|
|
*/ |
100
|
|
|
public function scopePublic(Builder $builder): Builder |
101
|
|
|
{ |
102
|
|
|
return $builder->where('is_public', true); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the private resources. |
107
|
|
|
* |
108
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
109
|
|
|
* |
110
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
111
|
|
|
*/ |
112
|
|
|
public function scopePrivate(Builder $builder): Builder |
113
|
|
|
{ |
114
|
|
|
return $builder->where('is_public', false); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the options for generating the slug. |
119
|
|
|
* |
120
|
|
|
* @return \Spatie\Sluggable\SlugOptions |
121
|
|
|
*/ |
122
|
|
|
public function getSlugOptions(): SlugOptions |
123
|
|
|
{ |
124
|
|
|
return SlugOptions::create() |
125
|
|
|
->doNotGenerateSlugsOnUpdate() |
126
|
|
|
->generateSlugsFrom('name') |
127
|
|
|
->saveSlugsTo('slug'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Activate the resource. |
132
|
|
|
* |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
public function makePublic() |
136
|
|
|
{ |
137
|
|
|
$this->update(['is_public' => true]); |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Deactivate the resource. |
144
|
|
|
* |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
|
|
public function makePrivate() |
148
|
|
|
{ |
149
|
|
|
$this->update(['is_public' => false]); |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|