1 | <?php namespace App\Models; |
||
8 | class Categories extends Model { |
||
9 | |||
10 | use SoftDeletes; |
||
11 | |||
12 | protected $table = 'categories'; |
||
13 | public $timestamps = true; |
||
14 | protected $dates = ['deleted_at']; |
||
15 | |||
16 | protected $guarded = ['category_id']; |
||
17 | protected $fillable = ['group_id', 'category_title', 'description', 'is_active']; |
||
18 | |||
19 | public function getKeyName(){ |
||
23 | |||
24 | /** |
||
25 | * Selects all the categories from the current group |
||
26 | * |
||
27 | * Allows to extend the query (scope) to only selects the categories from the group |
||
28 | * where the user is connected. |
||
29 | * @example Categories::group(); |
||
30 | * |
||
31 | * @param Object [Laravel] |
||
32 | */ |
||
33 | public function scopeFromGroup($query) { |
||
37 | |||
38 | /** |
||
39 | * Selects all the products from one category |
||
40 | * |
||
41 | * Easily fetch all the products that belongs to a category. Watch out, |
||
42 | * only works for ONE category. |
||
43 | * @example Categories::find(1)->products; |
||
44 | * |
||
45 | * @return Object [Laravel] |
||
46 | */ |
||
47 | public function products() { |
||
51 | |||
52 | } |