| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Models;
- use App\Models\Scopes\YearScope;
- use Illuminate\Database\Eloquent\Attributes\ScopedBy;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- 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;
- // 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();
- }
- });
- }
- protected $fillable = [
- 'year',
- 'order_number',
- '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);
- }
- }
|