MafOrder.php 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MafOrder extends Model
  10. {
  11. use SoftDeletes;
  12. protected static function boot(): void
  13. {
  14. parent::boot();
  15. static::creating(function($attributes) {
  16. if(!isset($attributes->year)) {
  17. $attributes->year = year();
  18. }
  19. });
  20. }
  21. protected $fillable = [
  22. 'year',
  23. 'order_number',
  24. 'status',
  25. 'user_id',
  26. 'product_id',
  27. 'quantity',
  28. 'in_stock',
  29. ];
  30. const DEFAULT_SORT_BY = 'created_at';
  31. public function user(): BelongsTo
  32. {
  33. return $this->belongsTo(User::class);
  34. }
  35. public function product(): BelongsTo
  36. {
  37. return $this->belongsTo(Product::class);
  38. }
  39. }