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 BookableAddon extends Model |
13
|
|
|
{ |
14
|
|
|
use ValidatingTrait; |
15
|
|
|
use CacheableEloquent; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $fillable = [ |
21
|
|
|
'bookable_id', |
22
|
|
|
'bookable_type', |
23
|
|
|
'slug', |
24
|
|
|
'name', |
25
|
|
|
'description', |
26
|
|
|
'base_cost', |
27
|
|
|
'base_cost_modifier', |
28
|
|
|
'unit_cost', |
29
|
|
|
'unit_cost_modifier', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected $casts = [ |
36
|
|
|
'bookable_id' => 'integer', |
37
|
|
|
'bookable_type' => 'string', |
38
|
|
|
'slug' => 'string', |
39
|
|
|
'base_cost' => 'float', |
40
|
|
|
'base_cost_modifier' => 'string', |
41
|
|
|
'unit_cost' => 'float', |
42
|
|
|
'unit_cost_modifier' => 'string', |
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
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Whether the model should throw a |
62
|
|
|
* ValidationException if it fails validation. |
63
|
|
|
* |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
protected $throwValidationExceptions = true; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Create a new Eloquent model instance. |
70
|
|
|
* |
71
|
|
|
* @param array $attributes |
72
|
|
|
*/ |
73
|
|
|
public function __construct(array $attributes = []) |
74
|
|
|
{ |
75
|
|
|
parent::__construct($attributes); |
76
|
|
|
|
77
|
|
|
$this->setTable(config('rinvex.bookings.tables.bookable_addons')); |
78
|
|
|
$this->setRules([ |
79
|
|
|
'bookable_id' => 'required|integer', |
80
|
|
|
'bookable_type' => 'required|string', |
81
|
|
|
'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.bookings.tables.bookable_addons').',slug,NULL,id,bookable_id,'.($this->bookable_id ?? 'null').',bookable_type,'.($this->bookable_type ?? 'null'), |
|
|
|
|
82
|
|
|
'name' => 'required|string|max:150', |
83
|
|
|
'description' => 'nullable|string|max:10000', |
84
|
|
|
'base_cost' => 'required|numeric', |
85
|
|
|
'base_cost_modifier' => 'required|string|in:+,-,×,÷', |
86
|
|
|
'unit_cost' => 'required|numeric', |
87
|
|
|
'unit_cost_modifier' => 'required|string|in:+,-,×,÷', |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the owning resource model. |
93
|
|
|
* |
94
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
95
|
|
|
*/ |
96
|
|
|
public function bookable(): MorphTo |
97
|
|
|
{ |
98
|
|
|
return $this->morphTo('bookable', 'bookable_type', 'bookable_id'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.