1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Bookings\Models; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Rinvex\Cacheable\CacheableEloquent; |
9
|
|
|
use Rinvex\Support\Traits\ValidatingTrait; |
10
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Rinvex\Bookings\Models\Price. |
14
|
|
|
* |
15
|
|
|
* @property int $id |
16
|
|
|
* @property int $bookable_id |
17
|
|
|
* @property string $bookable_type |
18
|
|
|
* @property \Carbon\Carbon $starts_at |
19
|
|
|
* @property \Carbon\Carbon $ends_at |
20
|
|
|
* @property float $percentage |
21
|
|
|
* @property \Carbon\Carbon|null $created_at |
22
|
|
|
* @property \Carbon\Carbon|null $updated_at |
23
|
|
|
* @property string $weekday |
24
|
|
|
* @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $bookable |
25
|
|
|
* |
26
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereCreatedAt($value) |
27
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereEndsAt($value) |
28
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereId($value) |
29
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price wherePercentage($value) |
30
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereBookableId($value) |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereBookableType($value) |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereStartsAt($value) |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereUpdatedAt($value) |
34
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereWeekday($value) |
35
|
|
|
* @mixin \Eloquent |
36
|
|
|
*/ |
37
|
|
|
class Price extends Model |
38
|
|
|
{ |
39
|
|
|
use ValidatingTrait; |
40
|
|
|
use CacheableEloquent; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected $fillable = [ |
46
|
|
|
'bookable_id', |
47
|
|
|
'bookable_type', |
48
|
|
|
'percentage', |
49
|
|
|
'weekday', |
50
|
|
|
'starts_at', |
51
|
|
|
'ends_at', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
protected $casts = [ |
58
|
|
|
'bookable_id' => 'integer', |
59
|
|
|
'bookable_type' => 'string', |
60
|
|
|
'percentage' => 'float', |
61
|
|
|
'weekday' => 'string', |
62
|
|
|
'starts_at' => 'string', |
63
|
|
|
'ends_at' => 'string', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
protected $observables = [ |
70
|
|
|
'validating', |
71
|
|
|
'validated', |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The default rules that the model will validate against. |
76
|
|
|
* |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
protected $rules = [ |
80
|
|
|
'bookable_id' => 'required|integer', |
81
|
|
|
'bookable_type' => 'required|string', |
82
|
|
|
'percentage' => 'required|numeric|min:-100|max:100', |
83
|
|
|
'weekday' => 'required|string|in:sun,mon,tue,wed,thu,fri,sat', |
84
|
|
|
'starts_at' => 'required|date_format:"H:i:s"', |
85
|
|
|
'ends_at' => 'required|date_format:"H:i:s"', |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Whether the model should throw a |
90
|
|
|
* ValidationException if it fails validation. |
91
|
|
|
* |
92
|
|
|
* @var bool |
93
|
|
|
*/ |
94
|
|
|
protected $throwValidationExceptions = true; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Create a new Eloquent model instance. |
98
|
|
|
* |
99
|
|
|
* @param array $attributes |
100
|
|
|
*/ |
101
|
|
|
public function __construct(array $attributes = []) |
102
|
|
|
{ |
103
|
|
|
parent::__construct($attributes); |
104
|
|
|
|
105
|
|
|
$this->setTable(config('rinvex.bookings.tables.prices')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get the owning resource model. |
110
|
|
|
* |
111
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
112
|
|
|
*/ |
113
|
|
|
public function bookable(): MorphTo |
114
|
|
|
{ |
115
|
|
|
return $this->morphTo(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|