TenantAtlas/app/Services/Inventory/DependencyQueryService.php

41 lines
1.3 KiB
PHP

<?php
namespace App\Services\Inventory;
use App\Models\InventoryItem;
use App\Models\InventoryLink;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
class DependencyQueryService
{
public function getOutboundEdges(InventoryItem $item, ?string $relationshipType = null, int $limit = 50): EloquentCollection
{
$query = InventoryLink::query()
->where('tenant_id', $item->tenant_id)
->where('source_type', 'inventory_item')
->where('source_id', $item->external_id)
->orderByDesc('created_at');
if ($relationshipType !== null) {
$query->where('relationship_type', $relationshipType);
}
return $query->limit($limit)->get();
}
public function getInboundEdges(InventoryItem $item, ?string $relationshipType = null, int $limit = 50): EloquentCollection
{
$query = InventoryLink::query()
->where('tenant_id', $item->tenant_id)
->where('target_type', 'inventory_item')
->where('target_id', $item->external_id)
->orderByDesc('created_at');
if ($relationshipType !== null) {
$query->where('relationship_type', $relationshipType);
}
return $query->limit($limit)->get();
}
}