|
|
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
+use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
@@ -40,11 +41,18 @@ class Order extends Model
|
|
|
'ready_to_mount',
|
|
|
];
|
|
|
|
|
|
+ public $appends = ['common_name'];
|
|
|
+
|
|
|
public function products_sku(): HasMany
|
|
|
{
|
|
|
return $this->hasMany(ProductSKU::class, 'order_id', 'id');
|
|
|
}
|
|
|
|
|
|
+ public function products(): HasManyThrough
|
|
|
+ {
|
|
|
+ return $this->hasManyThrough(Product::class, ProductSKU::class, 'order_id', 'id');
|
|
|
+ }
|
|
|
+
|
|
|
public function maf_orders(): BelongsTo
|
|
|
{
|
|
|
return $this->belongsTo(MafOrder::class, 'maf_order_id');
|
|
|
@@ -113,5 +121,12 @@ class Order extends Model
|
|
|
|
|
|
$this->update(['ready_to_mount' => ($result) ? 'Да' : 'Нет']);
|
|
|
}
|
|
|
+
|
|
|
+ public function commonName(): Attribute
|
|
|
+ {
|
|
|
+ return Attribute::make(
|
|
|
+ get: fn($value) => (string) $this->district->shortname . ', ' . $this->area->name . ', ' . $this->object_address,
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|