Completed
Push — develop ( 31dd7b...79ae1c )
by Abdelrahman
01:17
created

Tenant::getRouteKeyName()   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 Spatie\Activitylog\Traits\LogsActivity;
8
use Rinvex\Tenants\Models\Tenant as BaseTenant;
9
10
/**
11
 * Cortex\Tenants\Models\Tenant.
12
 *
13
 * @property int                                                                           $id
14
 * @property string                                                                        $slug
15
 * @property array                                                                         $name
16
 * @property array                                                                         $description
17
 * @property int                                                                           $owner_id
18
 * @property string                                                                        $email
19
 * @property string                                                                        $phone
20
 * @property string                                                                        $language_code
21
 * @property string                                                                        $country_code
22
 * @property string                                                                        $state
23
 * @property string                                                                        $city
24
 * @property string                                                                        $address
25
 * @property string                                                                        $postal_code
26
 * @property string                                                                        $launch_date
27
 * @property string                                                                        $group
28
 * @property bool                                                                          $is_active
29
 * @property \Carbon\Carbon|null                                                           $created_at
30
 * @property \Carbon\Carbon|null                                                           $updated_at
31
 * @property \Carbon\Carbon|null                                                           $deleted_at
32
 * @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity
33
 * @property-read \Cortex\Fort\Models\User                                                 $owner
34
 *
35
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant active()
36
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant inactive()
37
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereAddress($value)
38
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCity($value)
39
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCountryCode($value)
40
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCreatedAt($value)
41
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDeletedAt($value)
42
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDescription($value)
43
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereEmail($value)
44
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereGroup($value)
45
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereId($value)
46
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereIsActive($value)
47
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLanguageCode($value)
48
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLaunchDate($value)
49
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereName($value)
50
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereOwnerId($value)
51
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePhone($value)
52
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePostalCode($value)
53
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereSlug($value)
54
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereState($value)
55
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereUpdatedAt($value)
56
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant withGroup($group)
57
 * @mixin \Eloquent
58
 */
59
class Tenant extends BaseTenant
60
{
61
    use LogsActivity;
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected $fillable = [
67
        'slug',
68
        'name',
69
        'description',
70
        'owner_id',
71
        'email',
72
        'phone',
73
        'language_code',
74
        'country_code',
75
        'state',
76
        'city',
77
        'address',
78
        'postal_code',
79
        'launch_date',
80
        'group',
81
        'style',
82
        'is_active',
83
    ];
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    protected $casts = [
89
        'slug' => 'string',
90
        'owner_id' => 'integer',
91
        'email' => 'string',
92
        'phone' => 'string',
93
        'country_code' => 'string',
94
        'language_code' => 'string',
95
        'state' => 'string',
96
        'city' => 'string',
97
        'address' => 'string',
98
        'postal_code' => 'string',
99
        'launch_date' => 'string',
100
        'group' => 'string',
101
        'style' => 'string',
102
        'is_active' => 'boolean',
103
        'deleted_at' => 'datetime',
104
    ];
105
106
    /**
107
     * Indicates whether to log only dirty attributes or all.
108
     *
109
     * @var bool
110
     */
111
    protected static $logOnlyDirty = true;
112
113
    /**
114
     * The attributes that are logged on change.
115
     *
116
     * @var array
117
     */
118
    protected static $logAttributes = [
119
        'slug',
120
        'name',
121
        'description',
122
        'owner_id',
123
        'email',
124
        'phone',
125
        'language_code',
126
        'country_code',
127
        'state',
128
        'city',
129
        'address',
130
        'postal_code',
131
        'launch_date',
132
        'group',
133
        'style',
134
        'is_active',
135
    ];
136
137
    /**
138
     * The attributes that are ignored on change.
139
     *
140
     * @var array
141
     */
142
    protected static $ignoreChangedAttributes = [
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $ignoreChangedAttributes exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
143
        'created_at',
144
        'updated_at',
145
        'deleted_at',
146
    ];
147
148
    /**
149
     * Create a new Eloquent model instance.
150
     *
151
     * @param array $attributes
152
     */
153
    public function __construct(array $attributes = [])
154
    {
155
        parent::__construct($attributes);
156
157
        // Get users model
158
        $userModel = config('auth.providers.'.config('auth.guards.'.config('auth.defaults.guard').'.provider').'.model');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
159
160
        $this->setTable(config('rinvex.tenants.tables.tenants'));
161
        $this->setRules([
162
            'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.tenants.tables.tenants').',slug',
163
            'name' => 'required|string|max:150',
164
            'description' => 'nullable|string|max:10000',
165
            'owner_id' => 'required|integer|exists:'.(new $userModel())->getTable().',id',
166
            'email' => 'required|email|min:3|max:150|unique:'.config('rinvex.tenants.tables.tenants').',email',
167
            'phone' => 'nullable|numeric|min:4',
168
            'country_code' => 'required|alpha|size:2|country',
169
            'language_code' => 'required|alpha|size:2|language',
170
            'state' => 'nullable|string',
171
            'city' => 'nullable|string',
172
            'address' => 'nullable|string',
173
            'postal_code' => 'nullable|string',
174
            'launch_date' => 'nullable|date_format:Y-m-d',
175
            'group' => 'nullable|string|max:150',
176
            'style' => 'nullable|string|max:150',
177
            'is_active' => 'sometimes|boolean',
178
        ]);
179
    }
180
181
    /**
182
     * Get the route key for the model.
183
     *
184
     * @return string
185
     */
186
    public function getRouteKeyName()
187
    {
188
        return 'slug';
189
    }
190
}
191