Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ProductSpec | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
3.07 | |
0.00% |
0 / 1 |
| product | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| group | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| booted | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Models\admin\Product; |
| 6 | use App\Service\CacheService; |
| 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | |
| 9 | class ProductSpec extends Model |
| 10 | { |
| 11 | protected $fillable = [ |
| 12 | 'product_id', 'spec_group_id', 'label', 'value', 'is_filterable', 'sort_order', |
| 13 | ]; |
| 14 | |
| 15 | protected $casts = [ |
| 16 | 'is_filterable' => 'boolean', |
| 17 | 'sort_order' => 'integer', |
| 18 | ]; |
| 19 | |
| 20 | public function product() |
| 21 | { |
| 22 | return $this->belongsTo(Product::class); |
| 23 | } |
| 24 | |
| 25 | public function group() |
| 26 | { |
| 27 | return $this->belongsTo(SpecGroup::class, 'spec_group_id'); |
| 28 | } |
| 29 | |
| 30 | protected static function booted(): void |
| 31 | { |
| 32 | $bust = fn ($spec) => CacheService::forgetProduct($spec->product_id); |
| 33 | static::saved($bust); |
| 34 | static::deleted($bust); |
| 35 | } |
| 36 | } |