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
|
|
|
abstract class BookableRate extends Model |
13
|
|
|
{ |
14
|
|
|
use ValidatingTrait; |
15
|
|
|
use CacheableEloquent; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $fillable = [ |
21
|
|
|
'bookable_id', |
22
|
|
|
'bookable_type', |
23
|
|
|
'range', |
24
|
|
|
'from', |
25
|
|
|
'to', |
26
|
|
|
'base_cost', |
27
|
|
|
'unit_cost', |
28
|
|
|
'priority', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected $casts = [ |
35
|
|
|
'bookable_id' => 'integer', |
36
|
|
|
'bookable_type' => 'string', |
37
|
|
|
'range' => 'string', |
38
|
|
|
'from' => 'string', |
39
|
|
|
'to' => 'string', |
40
|
|
|
'base_cost' => 'float', |
41
|
|
|
'unit_cost' => 'float', |
42
|
|
|
'priority' => 'integer', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected $observables = [ |
49
|
|
|
'validating', |
50
|
|
|
'validated', |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The default rules that the model will validate against. |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $rules = [ |
59
|
|
|
'bookable_id' => 'required|integer', |
60
|
|
|
'bookable_type' => 'required|string', |
61
|
|
|
'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday', |
62
|
|
|
'from' => 'required|string|max:150', |
63
|
|
|
'to' => 'required|string|max:150', |
64
|
|
|
'base_cost' => 'nullable|numeric', |
65
|
|
|
'unit_cost' => 'required|numeric', |
66
|
|
|
'priority' => 'nullable|integer', |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Whether the model should throw a |
71
|
|
|
* ValidationException if it fails validation. |
72
|
|
|
* |
73
|
|
|
* @var bool |
74
|
|
|
*/ |
75
|
|
|
protected $throwValidationExceptions = true; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Create a new Eloquent model instance. |
79
|
|
|
* |
80
|
|
|
* @param array $attributes |
81
|
|
|
*/ |
82
|
|
|
public function __construct(array $attributes = []) |
83
|
|
|
{ |
84
|
|
|
parent::__construct($attributes); |
85
|
|
|
|
86
|
|
|
$this->setTable(config('rinvex.bookings.tables.bookable_rates')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the owning resource model. |
91
|
|
|
* |
92
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
93
|
|
|
*/ |
94
|
|
|
public function bookable(): MorphTo |
95
|
|
|
{ |
96
|
|
|
return $this->morphTo('bookable', 'bookable_type', 'bookable_id'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|