ProductSKU.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Scopes\YearScope;
  4. use Illuminate\Database\Eloquent\Attributes\ScopedBy;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. #[ScopedBy([YearScope::class])]
  9. class ProductSKU extends Model
  10. {
  11. use SoftDeletes;
  12. const DEFAULT_SORT_BY = 'created_at';
  13. protected $fillable = [
  14. 'year',
  15. 'product_id',
  16. 'order_id',
  17. 'maf_order_id',
  18. 'status', // needs - нуждается в данном товаре, related - привязана к MafOrder
  19. 'rfid',
  20. 'factory_number',
  21. 'manufacture_date',
  22. 'service_life',
  23. 'certificate_number',
  24. 'certificate_date',
  25. 'certificate_issuer',
  26. 'certificate_type',
  27. 'statement_number',
  28. 'statement_date',
  29. 'upd_number',
  30. 'comment',
  31. 'passport_id',
  32. ];
  33. public $table = 'products_sku';
  34. // set year attribute to current selected year
  35. protected static function boot(): void
  36. {
  37. parent::boot();
  38. static::creating(function($attributes) {
  39. if(!isset($attributes->year)) {
  40. $attributes->year = year();
  41. }
  42. });
  43. }
  44. /**
  45. * @return BelongsTo
  46. */
  47. public function product(): BelongsTo
  48. {
  49. return $this->belongsTo(Product::class, 'product_id', 'id');
  50. }
  51. /**
  52. * @return BelongsTo
  53. */
  54. public function order(): BelongsTo
  55. {
  56. return $this->belongsTo(Order::class, 'order_id', 'id');
  57. }
  58. /**
  59. * @return BelongsTo
  60. */
  61. public function passport(): BelongsTo
  62. {
  63. return $this->belongsTo(File::class, 'passport_id', 'id');
  64. }
  65. /**
  66. * @return BelongsTo
  67. */
  68. public function maf_order(): BelongsTo
  69. {
  70. return $this->belongsTo(MafOrder::class, 'maf_order_id', 'id');
  71. }
  72. }