Completed
Push — develop ( bb8d62...714b37 )
by Abdelrahman
08:38
created

Price::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
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
use Rinvex\Bookings\Contracts\PriceContract;
12
13
/**
14
 * Rinvex\Bookings\Models\Price.
15
 *
16
 * @property int                                                $id
17
 * @property int                                                $bookable_id
18
 * @property string                                             $bookable_type
19
 * @property string                                             $day
20
 * @property \Carbon\Carbon                                     $starts_at
21
 * @property \Carbon\Carbon                                     $ends_at
22
 * @property float                                              $price
23
 * @property \Carbon\Carbon|null                                $created_at
24
 * @property \Carbon\Carbon|null                                $updated_at
25
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $bookable
26
 *
27
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereBookableId($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereBookableType($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereCreatedAt($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereDay($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereEndsAt($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereId($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price wherePrice($value)
34
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereStartsAt($value)
35
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Price whereUpdatedAt($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
        'bookable_id',
48
        'bookable_type',
49
        'day',
50
        'starts_at',
51
        'ends_at',
52
        'price',
53
    ];
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected $casts = [
59
        'bookable_id' => 'integer',
60
        'bookable_type' => 'string',
61
        'day' => 'string',
62
        'starts_at' => 'datetime',
63
        'ends_at' => 'datetime',
64
        'price' => 'float',
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
            'bookable_id' => 'required|integer',
102
            'bookable_type' => 'required|string',
103
            'day' => 'in:sun,mon,tue,wed,thu,fri,sat',
104
            'starts_at' => 'nullable|time',
105
            'ends_at' => 'nullable|time',
106
            'price' => 'nullable|numeric',
107
        ]);
108
    }
109
110
    /**
111
     * Get the owning model.
112
     *
113
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
114
     */
115
    public function bookable(): MorphTo
116
    {
117
        return $this->morphTo();
118
    }
119
}
120