Page   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 72
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
A registerMediaCollections() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Pages\Models;
6
7
use Rinvex\Tags\Traits\Taggable;
8
use Rinvex\Tenants\Traits\Tenantable;
9
use Cortex\Foundation\Traits\Auditable;
10
use Rinvex\Support\Traits\HashidsTrait;
11
use Rinvex\Pages\Models\Page as BasePage;
12
use Spatie\MediaLibrary\HasMedia\HasMedia;
13
use Spatie\Activitylog\Traits\LogsActivity;
14
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
15
16
/**
17
 * Cortex\Pages\Models\Page.
18
 *
19
 * @property int                                                                           $id
20
 * @property string                                                                        $uri
21
 * @property string                                                                        $slug
22
 * @property string                                                                        $route
23
 * @property string                                                                        $domain
24
 * @property string                                                                        $middleware
25
 * @property array                                                                         $title
26
 * @property array                                                                         $subtitle
27
 * @property array                                                                         $excerpt
28
 * @property array                                                                         $content
29
 * @property string                                                                        $view
30
 * @property bool                                                                          $is_active
31
 * @property int                                                                           $sort_order
32
 * @property \Carbon\Carbon|null                                                           $created_at
33
 * @property \Carbon\Carbon|null                                                           $updated_at
34
 * @property \Carbon\Carbon|null                                                           $deleted_at
35
 * @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity
36
 * @property \Illuminate\Database\Eloquent\Collection|\Cortex\Tenants\Models\Tenant[]      $tenants
37
 *
38
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page ordered($direction = 'asc')
39
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereContent($value)
40
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereCreatedAt($value)
41
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereDeletedAt($value)
42
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereDomain($value)
43
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereExcerpt($value)
44
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereId($value)
45
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereIsActive($value)
46
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereMiddleware($value)
47
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereRoute($value)
48
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereSlug($value)
49
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereSortOrder($value)
50
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereSubtitle($value)
51
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereTitle($value)
52
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereUpdatedAt($value)
53
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereUri($value)
54
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereView($value)
55
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withAllTenants($tenants, $group = null)
56
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withAnyTenants($tenants, $group = null)
57
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withTenants($tenants, $group = null)
58
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withoutAnyTenants()
59
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withoutTenants($tenants, $group = null)
60
 * @mixin \Eloquent
61
 */
62
class Page extends BasePage implements HasMedia
63
{
64
    use Taggable;
65
    use Auditable;
66
    use Tenantable;
67
    use HashidsTrait;
68
    use LogsActivity;
69
    use HasMediaTrait;
70
71
    /**
72
     * Indicates whether to log only dirty attributes or all.
73
     *
74
     * @var bool
75
     */
76
    protected static $logOnlyDirty = true;
77
78
    /**
79
     * The attributes that are logged on change.
80
     *
81
     * @var array
82
     */
83
    protected static $logFillable = true;
84
85
    /**
86
     * The attributes that are ignored on change.
87
     *
88
     * @var array
89
     */
90
    protected static $ignoreChangedAttributes = [
91
        'created_at',
92
        'updated_at',
93
        'deleted_at',
94
    ];
95
96
    /**
97
     * Create a new Eloquent model instance.
98
     *
99
     * @param array $attributes
100
     */
101
    public function __construct(array $attributes = [])
102
    {
103
        parent::__construct($attributes);
104
105
        $this->setTable(config('rinvex.pages.tables.pages'));
106
        $this->setRules([
107
            'uri' => 'required|regex:/^([0-9a-z\/_-]+)$/|max:150|unique:'.config('rinvex.pages.tables.pages').',uri,NULL,id,domain,'.($this->domain ?? 'null'),
108
            'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.pages.tables.pages').',slug,NULL,id,domain,'.($this->domain ?? 'null'),
109
            'route' => 'required|regex:/^([0-9a-z\._-]+)$/|max:150|unique:'.config('rinvex.pages.tables.pages').',route,NULL,id,domain,'.($this->domain ?? 'null'),
110
            'domain' => 'nullable|string|max:150',
111
            'middleware' => 'nullable|string|max:150',
112
            'title' => 'required|string|max:150',
113
            'subtitle' => 'nullable|string|max:150',
114
            'excerpt' => 'nullable|string|max:10000',
115
            'content' => 'nullable|string|max:10000000',
116
            'view' => 'required|string|max:150',
117
            'is_active' => 'sometimes|boolean',
118
            'sort_order' => 'nullable|integer|max:10000000',
119
            'tags' => 'nullable|array',
120
        ]);
121
    }
122
123
    /**
124
     * Register media collections.
125
     *
126
     * @return void
127
     */
128
    public function registerMediaCollections(): void
129
    {
130
        $this->addMediaCollection('profile_picture')->singleFile();
131
        $this->addMediaCollection('cover_photo')->singleFile();
132
    }
133
}
134