1 | <?php namespace VojtaSvoboda\Brands\Models; |
||
8 | class Category extends Model |
||
9 | { |
||
10 | use SoftDeletingTrait; |
||
11 | |||
12 | use SortableTrait; |
||
13 | |||
14 | use ValidationTrait; |
||
15 | |||
16 | public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel']; |
||
17 | |||
18 | public $table = 'vojtasvoboda_brands_categories'; |
||
19 | |||
20 | public $rules = [ |
||
21 | 'name' => 'required|max:255', |
||
22 | 'slug' => 'required|unique:vojtasvoboda_brands_categories', |
||
23 | 'enabled' => 'boolean', |
||
24 | 'description' => 'max:10000', |
||
25 | ]; |
||
26 | |||
27 | public $translatable = ['name', 'slug', 'description']; |
||
28 | |||
29 | public $dates = ['created_at', 'updated_at', 'deleted_at']; |
||
30 | |||
31 | public $attachOne = [ |
||
32 | 'image' => ['System\Models\File'], |
||
33 | ]; |
||
34 | |||
35 | public $belongsToMany = [ |
||
36 | 'brands' => [ |
||
37 | 'VojtaSvoboda\Brands\Models\Brand', |
||
38 | 'table' => 'vojtasvoboda_brands_brand_category', |
||
39 | 'order' => 'name desc', |
||
40 | 'scope' => 'isEnabled', |
||
41 | 'timestamps' => true, |
||
42 | ], |
||
43 | ]; |
||
44 | |||
45 | public function scopeIsEnabled($query) |
||
49 | |||
50 | public function getBrandsCountAttribute() |
||
54 | } |
||
55 |