SparePartsView.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Models;
  3. class SparePartsView extends SparePart
  4. {
  5. protected $table = 'spare_parts_view';
  6. public $timestamps = false;
  7. public function pricingCodes(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
  8. {
  9. return $this->belongsToMany(PricingCode::class, 'spare_part_pricing_code', 'spare_part_id', 'pricing_code_id')
  10. ->withTimestamps();
  11. }
  12. public function getQuantityWithoutDocsAttribute(): int
  13. {
  14. if (array_key_exists('quantity_without_docs', $this->attributes)) {
  15. return (int) $this->attributes['quantity_without_docs'];
  16. }
  17. return parent::getQuantityWithoutDocsAttribute();
  18. }
  19. public function getQuantityWithDocsAttribute(): int
  20. {
  21. if (array_key_exists('quantity_with_docs', $this->attributes)) {
  22. return (int) $this->attributes['quantity_with_docs'];
  23. }
  24. return parent::getQuantityWithDocsAttribute();
  25. }
  26. public function getTotalQuantityAttribute(): int
  27. {
  28. if (array_key_exists('total_quantity', $this->attributes)) {
  29. return (int) $this->attributes['total_quantity'];
  30. }
  31. return parent::getTotalQuantityAttribute();
  32. }
  33. }