|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Models\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Spatie\Activitylog\LogOptions; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Facades\Cache; |
|
7
|
|
|
use drh2so4\Thumbnail\Traits\Thumbnail; |
|
|
|
|
|
|
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
9
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class Image extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
use LogsActivity, Thumbnail; |
|
14
|
|
|
|
|
15
|
|
|
protected $guarded = []; |
|
16
|
|
|
|
|
17
|
|
|
// Forget cache on updating or saving and deleting |
|
18
|
|
|
public static function boot() |
|
19
|
|
|
{ |
|
20
|
|
|
parent::boot(); |
|
21
|
|
|
|
|
22
|
|
|
static::saving(function () { |
|
23
|
|
|
self::cacheKey(); |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
static::deleting(function () { |
|
27
|
|
|
self::cacheKey(); |
|
28
|
|
|
}); |
|
29
|
|
|
|
|
30
|
|
|
Image::creating(function ($model) { |
|
31
|
|
|
$model->position = Image::max('position') + 1; |
|
32
|
|
|
}); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Cache Keys |
|
36
|
|
|
private static function cacheKey() |
|
37
|
|
|
{ |
|
38
|
|
|
Cache::has('images') ? Cache::forget('images') : ''; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Logs |
|
42
|
|
|
protected static $logName = 'image'; |
|
43
|
|
|
|
|
44
|
|
|
public function getActivitylogOptions(): LogOptions |
|
45
|
|
|
{ |
|
46
|
|
|
return LogOptions::defaults(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Appends |
|
50
|
|
|
protected $appends = ['network_image']; |
|
51
|
|
|
|
|
52
|
|
|
// Accessors |
|
53
|
|
|
public function getTypeAttribute($attribute) |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
1 => 'Normal', |
|
57
|
|
|
2 => 'Horizontal', |
|
58
|
|
|
3 => 'Vertical', |
|
59
|
|
|
4 => 'Slider', |
|
60
|
|
|
][$attribute]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// Relations |
|
64
|
|
|
public function gallery() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->belongsTo(Gallery::class, 'gallery_id'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Scopes |
|
70
|
|
|
public function scopeNormal($query) |
|
71
|
|
|
{ |
|
72
|
|
|
return $query->where('type', 1); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function scopeHorizontal($query) |
|
76
|
|
|
{ |
|
77
|
|
|
return $query->where('type', 2); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function scopeVertical($query) |
|
81
|
|
|
{ |
|
82
|
|
|
return $query->where('type', 3); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function scopeSlider($query) |
|
86
|
|
|
{ |
|
87
|
|
|
return $query->where('type', 4); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Accessors |
|
91
|
|
|
public function getNetworkImageAttribute() |
|
92
|
|
|
{ |
|
93
|
|
|
return isset($this->image) ? url('storage/'.$this->image) : null; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths