| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Models;
- use App\Models\Scopes\YearScope;
- use Illuminate\Database\Eloquent\Attributes\ScopedBy;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- #[ScopedBy([YearScope::class])]
- class MafOrder extends Model
- {
- use HasFactory, SoftDeletes;
- protected static function boot(): void
- {
- parent::boot();
- static::creating(function($attributes) {
- if(!isset($attributes->year)) {
- $attributes->year = year();
- }
- });
- }
- protected $fillable = [
- 'year',
- 'order_number',
- 'status',
- 'user_id',
- 'product_id',
- 'quantity',
- 'in_stock',
- ];
- const DEFAULT_SORT_BY = 'created_at';
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function product(): BelongsTo
- {
- return $this->belongsTo(Product::class);
- }
- public function products_sku(): HasMany
- {
- return $this->hasMany(ProductSKU::class);
- }
- }
|