I wrote a function where I pass an id parameter trough ItemRepository, and then I check if that item already belongs to another user. I think I made a mistake because every time it returns Exception I defined.
My Service:
public function itemCheck(User $user, $id)
{
/** @var Item $item */
$item = $this->getItemRepository()->find($id);
if(!$item) {
throw new AppClientException('Item not found!');
}
if($user->getId()) {
if($user->getId() == $item->getId()) {
return true;
} else {
throw new AppClientException('This item belongs to another user!!');
}
}
}