Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
44.44% |
4 / 9 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
| NotificationAttachment | |
44.44% |
4 / 9 |
|
16.67% |
1 / 6 |
12.17 | |
0.00% |
0 / 1 |
| casts | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| message | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| tenant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| uploadedBy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| existsOnDisk | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 8 | use Illuminate\Support\Facades\Storage; |
| 9 | |
| 10 | class NotificationAttachment extends Model |
| 11 | { |
| 12 | use HasFactory; |
| 13 | |
| 14 | protected $fillable = [ |
| 15 | 'notification_message_id', 'tenant_id', 'store_id', 'uploaded_by_user_id', 'disk', |
| 16 | 'path', 'original_name', 'mime_type', 'size_bytes', 'metadata', |
| 17 | ]; |
| 18 | |
| 19 | protected function casts(): array |
| 20 | { |
| 21 | return [ |
| 22 | 'size_bytes' => 'integer', |
| 23 | 'metadata' => 'array', |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | public function message(): BelongsTo { return $this->belongsTo(NotificationMessage::class, 'notification_message_id'); } |
| 28 | public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } |
| 29 | public function store(): BelongsTo { return $this->belongsTo(Store::class); } |
| 30 | public function uploadedBy(): BelongsTo { return $this->belongsTo(User::class, 'uploaded_by_user_id'); } |
| 31 | |
| 32 | public function existsOnDisk(): bool |
| 33 | { |
| 34 | return Storage::disk($this->disk)->exists($this->path); |
| 35 | } |
| 36 | } |