Completed
Push — develop ( c9eca1...366df2 )
by Abdelrahman
01:26
created

Tenant::managers()   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 Cortex\Tenants\Models;
6
7
use Cortex\Foundation\Traits\Auditable;
8
use Spatie\MediaLibrary\HasMedia\HasMedia;
9
use Spatie\Activitylog\Traits\LogsActivity;
10
use Rinvex\Tenants\Models\Tenant as BaseTenant;
11
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
12
use Illuminate\Database\Eloquent\Relations\MorphToMany;
13
14
/**
15
 * Cortex\Tenants\Models\Tenant.
16
 *
17
 * @property int                                                                           $id
18
 * @property string                                                                        $name
19
 * @property array                                                                         $title
20
 * @property array                                                                         $description
21
 * @property int                                                                           $owner_id
22
 * @property string                                                                        $owner_type
23
 * @property string                                                                        $email
24
 * @property string                                                                        $website
25
 * @property string                                                                        $phone
26
 * @property string                                                                        $language_code
27
 * @property string                                                                        $country_code
28
 * @property string                                                                        $state
29
 * @property string                                                                        $city
30
 * @property string                                                                        $address
31
 * @property string                                                                        $postal_code
32
 * @property string                                                                        $launch_date
33
 * @property string                                                                        $group
34
 * @property bool                                                                          $is_active
35
 * @property string                                                                        $style
36
 * @property \Carbon\Carbon|null                                                           $created_at
37
 * @property \Carbon\Carbon|null                                                           $updated_at
38
 * @property \Carbon\Carbon|null                                                           $deleted_at
39
 * @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity
40
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent                            $owner
41
 *
42
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant ofOwner(\Illuminate\Database\Eloquent\Model $owner)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 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...
43
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereAddress($value)
44
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCity($value)
45
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCountryCode($value)
46
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCreatedAt($value)
47
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDeletedAt($value)
48
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDescription($value)
49
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereEmail($value)
50
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereGroup($value)
51
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereId($value)
52
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereIsActive($value)
53
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLanguageCode($value)
54
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLaunchDate($value)
55
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereTitle($value)
56
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereOwnerId($value)
57
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereOwnerType($value)
58
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePhone($value)
59
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePostalCode($value)
60
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereName($value)
61
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereState($value)
62
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereUpdatedAt($value)
63
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereStyle($value)
64
 * @mixin \Eloquent
65
 */
66
class Tenant extends BaseTenant implements HasMedia
67
{
68
    use Auditable;
69
    use LogsActivity;
70
    use HasMediaTrait;
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    protected $fillable = [
76
        'name',
77
        'title',
78
        'description',
79
        'owner_id',
80
        'owner_type',
81
        'email',
82
        'website',
83
        'phone',
84
        'language_code',
85
        'country_code',
86
        'state',
87
        'city',
88
        'address',
89
        'postal_code',
90
        'launch_date',
91
        'group',
92
        'style',
93
        'is_active',
94
    ];
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    protected $casts = [
100
        'name' => 'string',
101
        'owner_id' => 'integer',
102
        'owner_type' => 'string',
103
        'email' => 'string',
104
        'website' => 'string',
105
        'phone' => 'string',
106
        'country_code' => 'string',
107
        'language_code' => 'string',
108
        'state' => 'string',
109
        'city' => 'string',
110
        'address' => 'string',
111
        'postal_code' => 'string',
112
        'launch_date' => 'string',
113
        'group' => 'string',
114
        'style' => 'string',
115
        'is_active' => 'boolean',
116
    ];
117
118
    /**
119
     * Indicates whether to log only dirty attributes or all.
120
     *
121
     * @var bool
122
     */
123
    protected static $logOnlyDirty = true;
124
125
    /**
126
     * The attributes that are logged on change.
127
     *
128
     * @var array
129
     */
130
    protected static $logFillable = true;
131
132
    /**
133
     * The attributes that are ignored on change.
134
     *
135
     * @var array
136
     */
137
    protected static $ignoreChangedAttributes = [
138
        'created_at',
139
        'updated_at',
140
        'deleted_at',
141
    ];
142
143
    /**
144
     * Create a new Eloquent model instance.
145
     *
146
     * @param array $attributes
147
     */
148
    public function __construct(array $attributes = [])
149
    {
150
        parent::__construct($attributes);
151
152
        $this->setTable(config('rinvex.tenants.tables.tenants'));
153
        $this->setRules([
154
            'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.tenants.tables.tenants').',name',
155
            'title' => 'required|string|max:150',
156
            'description' => 'nullable|string|max:10000',
157
            'owner_id' => 'required|integer',
158
            'owner_type' => 'required|string',
159
            'email' => 'required|email|min:3|max:150|unique:'.config('rinvex.tenants.tables.tenants').',email',
160
            'website' => 'nullable|string|max:150',
161
            'phone' => 'nullable|numeric|min:4',
162
            'country_code' => 'required|alpha|size:2|country',
163
            'language_code' => 'required|alpha|size:2|language',
164
            'state' => 'nullable|string',
165
            'city' => 'nullable|string',
166
            'address' => 'nullable|string',
167
            'postal_code' => 'nullable|string',
168
            'launch_date' => 'nullable|date_format:Y-m-d',
169
            'group' => 'nullable|string|max:150',
170
            'style' => 'nullable|string|max:150',
171
            'is_active' => 'sometimes|boolean',
172
        ]);
173
    }
174
175
    /**
176
     * Get the route key for the model.
177
     *
178
     * @return string
179
     */
180
    public function getRouteKeyName(): string
181
    {
182
        return 'name';
183
    }
184
185
    /**
186
     * Get all attached managers to tenant.
187
     *
188
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
189
     */
190
    public function managers(): MorphToMany
191
    {
192
        return $this->entries(config('cortex.auth.models.manager'));
193
    }
194
}
195