Completed
Push — develop ( 5e62e3...eaaeda )
by Abdelrahman
01:05
created

Rate::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\RateContract;
11
use Illuminate\Database\Eloquent\Relations\MorphTo;
12
13
/**
14
 * Rinvex\Bookings\Models\Rate.
15
 *
16
 * @property int                                                $id
17
 * @property int                                                $bookable_id
18
 * @property string                                             $bookable_type
19
 * @property int                                                $percentage
20
 * @property string                                             $operator
21
 * @property int                                                $amount
22
 * @property \Carbon\Carbon|null                                $created_at
23
 * @property \Carbon\Carbon|null                                $updated_at
24
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $bookable
25
 *
26
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereAmount($value)
27
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereBookableId($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereBookableType($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereCreatedAt($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereId($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereOperator($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate wherePercentage($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereUpdatedAt($value)
34
 * @mixin \Eloquent
35
 */
36
class Rate extends Model implements RateContract
37
{
38
    use ValidatingTrait;
39
    use CacheableEloquent;
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected $fillable = [
45
        'bookable_id',
46
        'bookable_type',
47
        'percentage',
48
        'operator',
49
        'amount',
50
    ];
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected $casts = [
56
        'bookable_id' => 'integer',
57
        'bookable_type' => 'string',
58
        'percentage' => 'integer',
59
        'operator' => 'string',
60
        'amount' => 'integer',
61
    ];
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected $observables = [
67
        'validating',
68
        'validated',
69
    ];
70
71
    /**
72
     * The default rules that the model will validate against.
73
     *
74
     * @var array
75
     */
76
    protected $rules = [];
77
78
    /**
79
     * Whether the model should throw a
80
     * ValidationException if it fails validation.
81
     *
82
     * @var bool
83
     */
84
    protected $throwValidationExceptions = true;
85
86
    /**
87
     * Create a new Eloquent model instance.
88
     *
89
     * @param array $attributes
90
     */
91
    public function __construct(array $attributes = [])
92
    {
93
        parent::__construct($attributes);
94
95
        $this->setTable(config('rinvex.bookings.tables.rates'));
96
        $this->setRules([
97
            'bookable_id' => 'required|integer',
98
            'bookable_type' => 'required|string',
99
            'percentage' => 'required|integer|min:-100|max:100',
100
            'operator' => 'required|in:^|>|<|=',
101
            'amount' => 'required|integer|max:10000000',
102
        ]);
103
    }
104
105
    /**
106
     * Get the owning model.
107
     *
108
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
109
     */
110
    public function bookable(): MorphTo
111
    {
112
        return $this->morphTo();
113
    }
114
}
115