1 | <?php |
||
18 | class TicketableTicket extends Model implements Sortable |
||
19 | { |
||
20 | use HasSlug; |
||
21 | use SortableTrait; |
||
22 | use HasTranslations; |
||
23 | use ValidatingTrait; |
||
24 | use CacheableEloquent; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | protected $fillable = [ |
||
30 | 'ticketable_id', |
||
31 | 'ticketable_type', |
||
32 | 'slug', |
||
33 | 'name', |
||
34 | 'description', |
||
35 | 'is_active', |
||
36 | 'price', |
||
37 | 'currency', |
||
38 | 'quantity', |
||
39 | 'sort_order', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | protected $casts = [ |
||
46 | 'ticketable_id' => 'integer', |
||
47 | 'ticketable_type' => 'string', |
||
48 | 'slug' => 'string', |
||
49 | 'name' => 'string', |
||
50 | 'description' => 'string', |
||
51 | 'is_active' => 'boolean', |
||
52 | 'price' => 'float', |
||
53 | 'currency' => 'string', |
||
54 | 'quantity' => 'integer', |
||
55 | 'sort_order' => 'integer', |
||
56 | 'deleted_at' => 'datetime', |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | protected $observables = [ |
||
63 | 'validating', |
||
64 | 'validated', |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public $translatable = [ |
||
71 | 'name', |
||
72 | 'description', |
||
73 | ]; |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public $sortable = [ |
||
79 | 'order_column_name' => 'sort_order', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * The default rules that the model will validate against. |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $rules = []; |
||
88 | |||
89 | /** |
||
90 | * Whether the model should throw a |
||
91 | * ValidationException if it fails validation. |
||
92 | * |
||
93 | * @var bool |
||
94 | */ |
||
95 | protected $throwValidationExceptions = true; |
||
96 | |||
97 | /** |
||
98 | * Create a new Eloquent model instance. |
||
99 | * |
||
100 | * @param array $attributes |
||
101 | */ |
||
102 | public function __construct(array $attributes = []) |
||
120 | |||
121 | /** |
||
122 | * Get the active resources. |
||
123 | * |
||
124 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
125 | * |
||
126 | * @return \Illuminate\Database\Eloquent\Builder |
||
127 | */ |
||
128 | public function scopeActive(Builder $builder): Builder |
||
132 | |||
133 | /** |
||
134 | * Get the inactive resources. |
||
135 | * |
||
136 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
137 | * |
||
138 | * @return \Illuminate\Database\Eloquent\Builder |
||
139 | */ |
||
140 | public function scopeInactive(Builder $builder): Builder |
||
144 | |||
145 | /** |
||
146 | * Get the options for generating the slug. |
||
147 | * |
||
148 | * @return \Spatie\Sluggable\SlugOptions |
||
149 | */ |
||
150 | public function getSlugOptions(): SlugOptions |
||
157 | |||
158 | /** |
||
159 | * Activate the resource. |
||
160 | * |
||
161 | * @return $this |
||
162 | */ |
||
163 | public function activate() |
||
164 | { |
||
165 | $this->update(['is_active' => true]); |
||
166 | |||
167 | return $this; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Deactivate the resource. |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | public function deactivate() |
||
176 | { |
||
177 | $this->update(['is_active' => false]); |
||
178 | |||
179 | return $this; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Get the owning resource model. |
||
184 | * |
||
185 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
186 | */ |
||
187 | public function ticketable(): MorphTo |
||
191 | } |
||
192 |