|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App; |
|
4
|
|
|
|
|
5
|
|
|
use App\Libraries\Categoryable\Categoryable; |
|
6
|
|
|
use App\Libraries\Presenterable\Presenterable; |
|
7
|
|
|
use App\Libraries\Presenterable\Presenters\CategoryPresenter; |
|
8
|
|
|
use App\Traits\ActivateableTrait; |
|
9
|
|
|
use App\Traits\Categories\HasFilters; |
|
10
|
|
|
use App\Traits\HasImages; |
|
11
|
|
|
use App\Traits\RankedableTrait; |
|
12
|
|
|
use Keyhunter\Administrator\Repository; |
|
13
|
|
|
use Keyhunter\Translatable\HasTranslations; |
|
14
|
|
|
|
|
15
|
|
|
class Category extends Repository |
|
16
|
|
|
{ |
|
17
|
|
|
use HasTranslations, |
|
18
|
|
|
ActivateableTrait, |
|
19
|
|
|
RankedableTrait, |
|
20
|
|
|
HasImages, |
|
21
|
|
|
Presenterable, |
|
22
|
|
|
HasFilters; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $table = 'categories'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var CategoryPresenter |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $presenter = CategoryPresenter::class; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var CategoryTranslation |
|
36
|
|
|
*/ |
|
37
|
|
|
public $translationModel = CategoryTranslation::class; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $fillable = ['tax', 'active', 'show_in_footer', 'show_in_sidebar', 'rank']; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
public $translatedAttributes = ['name', 'slug', 'seo_title', 'seo_description', 'seo_keywords']; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
51
|
|
|
*/ |
|
52
|
|
|
public function subCategories() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->hasMany(SubCategory::class, 'category_id', 'id'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough |
|
59
|
|
|
*/ |
|
60
|
|
|
public function products() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->hasManyThrough( |
|
63
|
|
|
Product::class, SubCategory::class, |
|
64
|
|
|
'category_id', 'sub_category_id', 'id' |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
70
|
|
|
*/ |
|
71
|
|
|
public function categoryables() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->hasMany(Categoryable::class, 'category_id', 'id'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
78
|
|
|
*/ |
|
79
|
|
|
public function tags() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->hasMany(Tag::class, 'category_id', 'id'); |
|
82
|
|
|
} |
|
83
|
|
|
} |