Completed
Push — master ( 7d04c8...2a4aa6 )
by Jan
10:55
created

Image   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 4
dl 0
loc 138
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A imagecategories() 0 4 1
A slides() 0 4 1
A articlecategories() 0 4 1
A pages() 0 4 1
A scopeRelationships() 0 4 1
A hide() 0 4 1
1
<?php
2
/**
3
 * Image module model
4
 * 
5
 * Model for module Image
6
 * 
7
 * @category Model
8
 * @subpackage Admin
9
 * @package Olapus
10
 * @author Jan Drda <[email protected]>
11
 * @copyright Jan Drda
12
 * @license https://opensource.org/licenses/MIT MIT
13
 */
14
namespace App;
15
16
use Illuminate\Database\Eloquent\Model;
17
use Illuminate\Database\Eloquent\SoftDeletes;
18
use Spatie\MediaLibrary\HasMedia\HasMedia;
19
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
20
21
class Image extends Model implements HasMedia
22
{
23
    use SoftDeletes, AdminModelTrait, HasMediaTrait;
24
    
25
    /**
26
     * The database table used by the model.
27
     *
28
     * @var string
29
     */
30
    protected $table = 'image';
31
    
32
    /**
33
     * The attributes that should be mutated to dates.
34
     *
35
     * @var array
36
     */
37
    protected $dates = ['created_at', 'updated_at', 'deleted_at'];
38
    
39
    /**
40
     * The attributes that are mass assignable.
41
     *
42
     * @var array
43
     */
44
    protected $fillable = ['name', 'description', 'alt', 'url'];
45
    
46
    /**
47
     * Columns to exclude from index
48
     * 
49
     * @var array 
50
     */
51
    protected $excludedFromIndex = [];
52
    
53
    /**
54
     * Hidden from custom find
55
     * 
56
     * @var arrat 
57
     */
58
    protected  $excludedFromFind = [];
59
    
60
    /**
61
     * Fields to search in fulltext mode
62
     * 
63
     * @var array
64
     */
65
    protected $fulltextFields = [
66
        'id',
67
        'name' => [
68
            'operator' => 'LIKE',
69
            'prefix' => '%',
70
            'sufix' => '%'
71
        ],
72
        'description' => [
73
            'operator' => 'LIKE',
74
            'prefix' => '%',
75
            'sufix' => '%'
76
        ],
77
        'alt' => [
78
            'operator' => 'LIKE',
79
            'prefix' => '%',
80
            'sufix' => '%'
81
        ],
82
        'url' => [
83
            'operator' => 'LIKE',
84
            'prefix' => '%',
85
            'sufix' => '%'
86
        ],
87
    ];
88
    
89
    /**
90
     * Default order by
91
     * 
92
     * @type array
93
     */
94
    protected $defaultOrderBy = [
95
      'id' => 'desc'  
96
    ];
97
    
98
    /**
99
     * Image category link
100
     * 
101
     * @return object
102
     */
103
    public function imagecategories(){
104
        
105
        return $this->belongsTo('App\ImageCategory', 'imagecategory_id');
106
    }
107
    
108
    /**
109
     * Slide link
110
     * 
111
     * @return object
112
     */
113
    public function slides(){
114
        
115
        return $this->hasMany('App\Slide', 'image_id');
116
    }
117
    
118
    /**
119
     * Article category
120
     * 
121
     * @return object
122
     */
123
    public function articlecategories(){
124
        
125
        return $this->hasMany('App\ArticleCategory', 'image_id');
126
    }
127
    
128
    /**
129
     * Article category
130
     * 
131
     * @return object
132
     */
133
    public function pages(){
134
        
135
        return $this->hasMany('App\Page', 'image_id');
136
    }
137
    
138
    /**
139
     * Process relationships
140
     * 
141
     * @param query $query
142
     * @return query
143
     */
144
    public function scopeRelationships($query){
145
        
146
        return $query->with('imagecategories');
147
    }
148
    
149
    /**
150
     * Hide fields
151
     * 
152
     * @param array $array
153
     */
154
    public function hide($array = []){
155
        
156
        $this->hidden = ['image'];
157
    }
158
}
159