1 | <?php |
||
18 | abstract class Bookable extends Model implements Sortable |
||
19 | { |
||
20 | use HasSlug; |
||
21 | use BookableTrait; |
||
22 | use SortableTrait; |
||
23 | use HasTranslations; |
||
24 | use ValidatingTrait; |
||
25 | use CacheableEloquent; |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | protected $fillable = [ |
||
31 | 'slug', |
||
32 | 'name', |
||
33 | 'description', |
||
34 | 'is_active', |
||
35 | 'base_cost', |
||
36 | 'unit_cost', |
||
37 | 'currency', |
||
38 | 'unit', |
||
39 | 'maximum_units', |
||
40 | 'minimum_units', |
||
41 | 'is_cancelable', |
||
42 | 'is_recurring', |
||
43 | 'sort_order', |
||
44 | 'capacity', |
||
45 | 'style', |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | protected $casts = [ |
||
52 | 'slug' => 'string', |
||
53 | 'name' => 'string', |
||
54 | 'description' => 'string', |
||
55 | 'is_active' => 'boolean', |
||
56 | 'base_cost' => 'float', |
||
57 | 'unit_cost' => 'float', |
||
58 | 'currency' => 'string', |
||
59 | 'unit' => 'string', |
||
60 | 'maximum_units' => 'integer', |
||
61 | 'minimum_units' => 'integer', |
||
62 | 'is_cancelable' => 'boolean', |
||
63 | 'is_recurring' => 'boolean', |
||
64 | 'sort_order' => 'integer', |
||
65 | 'capacity' => 'integer', |
||
66 | 'style' => 'string', |
||
67 | 'deleted_at' => 'datetime', |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | protected $observables = [ |
||
74 | 'validating', |
||
75 | 'validated', |
||
76 | ]; |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public $translatable = [ |
||
82 | 'name', |
||
83 | 'description', |
||
84 | ]; |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public $sortable = [ |
||
90 | 'order_column_name' => 'sort_order', |
||
91 | ]; |
||
92 | |||
93 | /** |
||
94 | * The default rules that the model will validate against. |
||
95 | * |
||
96 | * @var array |
||
97 | */ |
||
98 | protected $rules = [ |
||
99 | 'slug' => 'required|alpha_dash|max:150', |
||
100 | 'name' => 'required|string|max:150', |
||
101 | 'description' => 'nullable|string|max:10000', |
||
102 | 'is_active' => 'sometimes|boolean', |
||
103 | 'base_cost' => 'required|numeric', |
||
104 | 'unit_cost' => 'required|numeric', |
||
105 | 'currency' => 'required|string|size:3', |
||
106 | 'unit' => 'required|in:minute,hour,day,month', |
||
107 | 'maximum_units' => 'nullable|integer|max:10000', |
||
108 | 'minimum_units' => 'nullable|integer|max:10000', |
||
109 | 'is_cancelable' => 'nullable|boolean', |
||
110 | 'is_recurring' => 'nullable|boolean', |
||
111 | 'sort_order' => 'nullable|integer|max:10000000', |
||
112 | 'capacity' => 'nullable|integer|max:10000000', |
||
113 | 'style' => 'nullable|string|max:150', |
||
114 | ]; |
||
115 | |||
116 | /** |
||
117 | * Get the active resources. |
||
118 | * |
||
119 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
120 | * |
||
121 | * @return \Illuminate\Database\Eloquent\Builder |
||
122 | */ |
||
123 | public function scopeActive(Builder $builder): Builder |
||
127 | |||
128 | /** |
||
129 | * Get the inactive resources. |
||
130 | * |
||
131 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
132 | * |
||
133 | * @return \Illuminate\Database\Eloquent\Builder |
||
134 | */ |
||
135 | public function scopeInactive(Builder $builder): Builder |
||
139 | |||
140 | /** |
||
141 | * Get the options for generating the slug. |
||
142 | * |
||
143 | * @return \Spatie\Sluggable\SlugOptions |
||
144 | */ |
||
145 | public function getSlugOptions(): SlugOptions |
||
152 | |||
153 | /** |
||
154 | * Activate the resource. |
||
155 | * |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function activate() |
||
164 | |||
165 | /** |
||
166 | * Deactivate the resource. |
||
167 | * |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function deactivate() |
||
176 | } |
||
177 |