belongsTo(User::class, 'user_id'); } public function recipe() { return $this->belongsTo(Recipe::class, 'recipe_id'); } public function upvotes(): HasMany { return $this->hasMany(RecipeCommentUpvote::class, 'recipe_comment_id'); } public function isUpVoted(): bool { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsUpVote($this) ->count(); } return false; } public function isDownVoted(): bool { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsDownVote($this) ->count(); } return false; } public function removeUpVote(): bool { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsUpVote($this) ->delete(); } return false; } public function removeDownVote(): bool { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsDownVote($this) ->delete(); } return false; } }