hasMany(InventoryMovement::class)->where('movement_type', 'entry'); } public function suppliedProducts() { return $this->hasManyThrough(Inventory::class, InventoryMovement::class, 'supplier_id', 'id', 'id', 'product_id') ->where('inventory_movements.movement_type', 'entry') ->distinct(); } }