Completed
Push — develop ( 714b37...8cdca7 )
by Abdelrahman
04:46
created

Price::bookable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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