$upvotes * @property-read int|null $upvotes_count * * @method static \Database\Factories\RecipeCommentFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment newQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment query() * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereBody($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereGrade($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereRecipeId($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereUserId($value) * * @mixin \Eloquent */ class RecipeComment extends Model { use HasFactory; public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public function recipe(): BelongsTo { return $this->belongsTo(Recipe::class, 'recipe_id'); } public function upvotes(): HasMany { return $this->hasMany(RecipeCommentUpvote::class, 'recipe_comment_id'); } public function isUpVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsUpVote($this) ->count(); } return false; } public function isDownVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsDownVote($this) ->count(); } return false; } public function removeUpVote(): bool|int { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsUpVote($this) ->delete(); } return false; } public function removeDownVote(): bool|int { $curUser = auth()->user(); if ($curUser) { return $curUser ->recipe_comment_upvotes() ->forRecipeCommentsDownVote($this) ->delete(); } return false; } }