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