ProductSKU.php 1.7 KB

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