ProductSKU.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. ];
  32. public $table = 'products_sku';
  33. // set year attribute to current selected year
  34. protected static function boot(): void
  35. {
  36. parent::boot();
  37. static::creating(function($attributes) {
  38. if(!isset($attributes->year)) {
  39. $attributes->year = year();
  40. }
  41. });
  42. }
  43. /**
  44. * @return BelongsTo
  45. */
  46. public function product(): BelongsTo
  47. {
  48. return $this->belongsTo(Product::class, 'product_id', 'id');
  49. }
  50. /**
  51. * @return BelongsTo
  52. */
  53. public function order(): BelongsTo
  54. {
  55. return $this->belongsTo(Order::class, 'order_id', 'id');
  56. }
  57. /**
  58. * @return BelongsTo
  59. */
  60. public function maf_order(): BelongsTo
  61. {
  62. return $this->belongsTo(MafOrder::class, 'maf_order_id', 'id');
  63. }
  64. }