|
|
@@ -7,7 +7,9 @@ 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\Relations\BelongsToMany;
|
|
|
+use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
@@ -112,6 +114,23 @@ class Product extends Model
|
|
|
return $this->belongsToMany(Order::class, 'products_sku', 'order_id', 'product_id');
|
|
|
}
|
|
|
|
|
|
+ public function products_sku(): HasOne
|
|
|
+ {
|
|
|
+ return $this->hasOne(ProductSku::class, 'product_id', 'id');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function hasRelations(): bool
|
|
|
+ {
|
|
|
+ if($this->products_sku && ($this->products_sku->count() > 0)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->orders && ($this->orders->count() > 0)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|