ProductionOrderItem.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Models;
  4. use Database\Factories\ProductionOrderItemFactory;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  8. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  9. use Illuminate\Database\Eloquent\SoftDeletes;
  10. class ProductionOrderItem extends Model
  11. {
  12. /** @use HasFactory<ProductionOrderItemFactory> */
  13. use HasFactory;
  14. use SoftDeletes;
  15. protected $fillable = [
  16. 'production_order_id',
  17. 'common_catalog_item_id',
  18. 'external_id',
  19. 'order_item_number',
  20. 'factory_number',
  21. 'manufacture_date',
  22. 'passport_file_id',
  23. 'sort',
  24. 'created_by',
  25. ];
  26. protected function casts(): array
  27. {
  28. return [
  29. 'production_order_id' => 'integer',
  30. 'common_catalog_item_id' => 'integer',
  31. 'manufacture_date' => 'immutable_date',
  32. 'passport_file_id' => 'integer',
  33. 'sort' => 'integer',
  34. 'created_by' => 'integer',
  35. ];
  36. }
  37. public function productionOrder(): BelongsTo
  38. {
  39. return $this->belongsTo(ProductionOrder::class);
  40. }
  41. public function catalogItem(): BelongsTo
  42. {
  43. return $this->belongsTo(CommonCatalogItem::class, 'common_catalog_item_id');
  44. }
  45. public function passportFile(): BelongsTo
  46. {
  47. return $this->belongsTo(File::class, 'passport_file_id');
  48. }
  49. public function creator(): BelongsTo
  50. {
  51. return $this->belongsTo(User::class, 'created_by');
  52. }
  53. public function reclamations(): BelongsToMany
  54. {
  55. return $this->belongsToMany(Reclamation::class, 'production_order_item_reclamation')
  56. ->withTimestamps();
  57. }
  58. }