Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ShortcutSubCategoryLv1 | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
boot | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
ShortcutCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shortcuts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getShortcutsCountAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
subCategoryLv2 | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Http\Models; |
4 | |
5 | use App\Observers\ShortcutSubCategoryLv1Observer; |
6 | use Illuminate\Database\Eloquent\Attributes\ObservedBy; |
7 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
8 | use Illuminate\Notifications\Notifiable; |
9 | |
10 | #[ObservedBy([ShortcutSubCategoryLv1Observer::class])] |
11 | class ShortcutSubCategoryLv1 extends Moloquent |
12 | { |
13 | use HasFactory, Notifiable; |
14 | |
15 | protected $table = 'shortcut_sub_categories_lv1'; |
16 | |
17 | protected $fillable = [ |
18 | 'name', |
19 | 'user_id', |
20 | 'seq_id', |
21 | 'category_id', |
22 | 'sub_categories_lv2' |
23 | ]; |
24 | |
25 | protected $appends = ['shortcuts_count']; |
26 | |
27 | protected static function boot() |
28 | { |
29 | parent::boot(); |
30 | |
31 | static::deleting(function ($category) { |
32 | $category->subCategoryLv2()->delete(); |
33 | }); |
34 | } |
35 | |
36 | public function ShortcutCategory() |
37 | { |
38 | return $this->belongsTo(ShortcutCategory::class, 'category_id'); |
39 | } |
40 | |
41 | public function shortcuts() |
42 | { |
43 | return $this->hasMany(Shortcut::class, 'sub_categories_lv1_id'); |
44 | } |
45 | |
46 | public function getShortcutsCountAttribute() |
47 | { |
48 | return $this->shortcuts()->count(); |
49 | } |
50 | |
51 | public function subCategoryLv2() |
52 | { |
53 | return $this->hasMany(ShortcutSubCategoryLv2::class, 'sub_categories_lv1')->orderBy('seq_id', 'ASC'); |
54 | } |
55 | } |