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