| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Models;
- use App\Models\Scopes\YearScope;
- use Illuminate\Database\Eloquent\Attributes\ScopedBy;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\SoftDeletes;
- #[ScopedBy([YearScope::class])]
- class ProductSKU extends Model
- {
- use SoftDeletes;
- const DEFAULT_SORT_BY = 'created_at';
- protected $fillable = [
- 'year',
- 'product_id',
- 'order_id',
- 'maf_order_id',
- 'status', // needs - нуждается в данном товаре, related - привязана к MafOrder
- 'rfid',
- 'factory_number',
- 'manufacture_date',
- 'statement_number',
- 'statement_date',
- 'upd_number',
- 'comment',
- 'passport_id',
- ];
- public $table = 'products_sku';
- // set year attribute to current selected year
- protected static function boot(): void
- {
- parent::boot();
- static::creating(function($attributes) {
- if(!isset($attributes->year)) {
- $attributes->year = year();
- }
- });
- }
- /**
- * @return BelongsTo
- */
- public function product(): BelongsTo
- {
- return $this->belongsTo(Product::class, 'product_id', 'id')->withoutGlobalScopes();
- }
- /**
- * @return BelongsTo
- */
- public function order(): BelongsTo
- {
- return $this->belongsTo(Order::class, 'order_id', 'id');
- }
- /**
- * @return BelongsTo
- */
- public function passport(): BelongsTo
- {
- return $this->belongsTo(File::class, 'passport_id', 'id');
- }
- /**
- * @return BelongsTo
- */
- public function maf_order(): BelongsTo
- {
- return $this->belongsTo(MafOrder::class, 'maf_order_id', 'id')->withoutGlobalScopes();
- }
- }
|