|
|
@@ -5,6 +5,8 @@ namespace App\Models;
|
|
|
use App\Helpers\Price;
|
|
|
use App\Models\Dictionary\Area;
|
|
|
use App\Models\Dictionary\District;
|
|
|
+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;
|
|
|
@@ -14,6 +16,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
+#[ScopedBy([YearScope::class])]
|
|
|
class Order extends Model
|
|
|
{
|
|
|
use SoftDeletes;
|
|
|
@@ -24,7 +27,19 @@ class Order extends Model
|
|
|
const STATUS_READY_TO_HAND_OVER = 3;
|
|
|
const STATUS_HANDED_OVER = 4;
|
|
|
|
|
|
+ // 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',
|
|
|
'user_id',
|
|
|
'district_id',
|
|
|
'area_id',
|