Completed
Push — develop ( 3de1d7...233a23 )
by Abdelrahman
01:42
created

BookableAvailability::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
12
abstract class BookableAvailability extends Model
13
{
14
    use ValidatingTrait;
15
    use CacheableEloquent;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $fillable = [
21
        'bookable_id',
22
        'bookable_type',
23
        'is_available',
24
        'range',
25
        'range_from',
26
        'range_to',
27
        'priority',
28
    ];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $casts = [
34
        'bookable_id' => 'integer',
35
        'bookable_type' => 'string',
36
        'is_available' => 'boolean',
37
        'range' => 'string',
38
        'range_from' => 'string',
39
        'range_to' => 'string',
40
        'priority' => 'integer',
41
    ];
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected $observables = [
47
        'validating',
48
        'validated',
49
    ];
50
51
    /**
52
     * The default rules that the model will validate against.
53
     *
54
     * @var array
55
     */
56
    protected $rules = [
57
        'bookable_id' => 'required|integer',
58
        'bookable_type' => 'required|string',
59
        'is_available' => 'required|boolean',
60
        '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...
61
        'range_from' => 'required|string|max:150',
62
        'range_to' => 'required|string|max:150',
63
        'priority' => 'nullable|integer',
64
    ];
65
66
    /**
67
     * Whether the model should throw a
68
     * ValidationException if it fails validation.
69
     *
70
     * @var bool
71
     */
72
    protected $throwValidationExceptions = true;
73
74
    /**
75
     * Create a new Eloquent model instance.
76
     *
77
     * @param array $attributes
78
     */
79
    public function __construct(array $attributes = [])
80
    {
81
        parent::__construct($attributes);
82
83
        $this->setTable(config('rinvex.bookings.tables.bookable_availabilities'));
84
    }
85
86
    /**
87
     * Get the owning resource model.
88
     *
89
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
90
     */
91
    public function bookable(): MorphTo
92
    {
93
        return $this->morphTo('bookable', 'bookable_type', 'bookable_id');
94
    }
95
}
96