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