| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?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 MafOrder extends Model
- {
- use 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);
- }
- }
|