|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Models\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Traits\CategoryMorphedByMany; |
|
|
|
|
|
|
6
|
|
|
use drh2so4\Thumbnail\Traits\Thumbnail; |
|
|
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class Category extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
use LogsActivity, Thumbnail, CategoryMorphedByMany; |
|
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
|
|
|
Category::creating(function ($model) { |
|
31
|
|
|
$model->position = Category::max('position') + 1; |
|
32
|
|
|
}); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Cache Keys |
|
36
|
|
|
private static function cacheKey() |
|
37
|
|
|
{ |
|
38
|
|
|
Cache::has('categories') ? Cache::forget('categories') : ''; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Logs |
|
42
|
|
|
protected static $logName = 'category'; |
|
43
|
|
|
|
|
44
|
|
|
public function getActivitylogOptions(): LogOptions |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
return LogOptions::defaults(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected $parentColumn = 'category_id'; |
|
50
|
|
|
|
|
51
|
|
|
protected $casts = [ |
|
52
|
|
|
'meta_keywords' => 'array', |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
// Relation |
|
56
|
|
|
public function categorizable() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->morphTo(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function parent() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->belongsTo(Category::class, $this->parentColumn); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function categories() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->hasMany(Category::class); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function childrenCategories() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->hasMany(Category::class)->with('categories'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// Scopes |
|
77
|
|
|
|
|
78
|
|
|
public function scopePositionCategory($query, $limit = 4) |
|
79
|
|
|
{ |
|
80
|
|
|
return $query->with('children')->orderBy('position', 'desc')->take($limit); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function scopeActive($query) |
|
84
|
|
|
{ |
|
85
|
|
|
return $query->where('active', 1); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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