Completed
Push — develop ( 973520...768b39 )
by Abdelrahman
01:27
created

Availability::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 Illuminate\Database\Eloquent\Relations\MorphTo;
11
12
/**
13
 * Rinvex\Bookings\Models\Availability.
14
 *
15
 * @property int                                                $id
16
 * @property int                                                $bookable_id
17
 * @property string                                             $bookable_type
18
 * @property int                                                $is_available
19
 * @property string                                             $range
20
 * @property string                                             $range_from
21
 * @property string                                             $range_to
22
 * @property int                                                $priority
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\Availability whereCreatedAt($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereId($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereBookableId($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereBookableType($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereIsAvailable($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereRange($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereRangeFrom($value)
34
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereRangeTo($value)
35
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability wherePriority($value)
36
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereUpdatedAt($value)
37
 * @mixin \Eloquent
38
 */
39
class Availability extends Model
40
{
41
    use ValidatingTrait;
42
    use CacheableEloquent;
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected $fillable = [
48
        'bookable_id',
49
        'bookable_type',
50
        'is_available',
51
        'range',
52
        'range_from',
53
        'range_to',
54
        'priority',
55
    ];
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    protected $casts = [
61
        'bookable_id' => 'integer',
62
        'bookable_type' => 'string',
63
        'is_available' => 'boolean',
64
        'range' => 'string',
65
        'range_from' => 'string',
66
        'range_to' => 'string',
67
        'priority' => 'integer',
68
    ];
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected $observables = [
74
        'validating',
75
        'validated',
76
    ];
77
78
    /**
79
     * The default rules that the model will validate against.
80
     *
81
     * @var array
82
     */
83
    protected $rules = [
84
        'bookable_id' => 'required|integer',
85
        'bookable_type' => 'required|string',
86
        'is_available' => 'required|boolean',
87
        'range' => 'required|string|in:unit,date,month,week,day,datetime,time,time-sun,time-mon,time-tue,time-wed,time-thu,time-fri,time-sat',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

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.

Loading history...
88
        'range_from' => 'required|string|max:150',
89
        'range_to' => 'required|string|max:150',
90
        'priority' => 'nullable|integer',
91
    ];
92
93
    /**
94
     * Whether the model should throw a
95
     * ValidationException if it fails validation.
96
     *
97
     * @var bool
98
     */
99
    protected $throwValidationExceptions = true;
100
101
    /**
102
     * Create a new Eloquent model instance.
103
     *
104
     * @param array $attributes
105
     */
106
    public function __construct(array $attributes = [])
107
    {
108
        parent::__construct($attributes);
109
110
        $this->setTable(config('rinvex.bookings.tables.availabilities'));
111
    }
112
113
    /**
114
     * Get the owning resource model.
115
     *
116
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
117
     */
118
    public function bookable(): MorphTo
119
    {
120
        return $this->morphTo('bookable', 'bookable_type', 'bookable_id');
121
    }
122
}
123