where('user_id', $user->id) ->where('card_id', $card->id) ->where('type', $type) ->first(); if ($active && ! $existing) { NovaCardReaction::query()->create([ 'user_id' => $user->id, 'card_id' => $card->id, 'type' => $type, ]); } if (! $active && $existing) { $existing->delete(); } UpdateNovaCardStatsJob::dispatch($card->id); $card->refresh(); return [ 'liked' => NovaCardReaction::query()->where('user_id', $user->id)->where('card_id', $card->id)->where('type', NovaCardReaction::TYPE_LIKE)->exists(), 'favorited' => NovaCardReaction::query()->where('user_id', $user->id)->where('card_id', $card->id)->where('type', NovaCardReaction::TYPE_FAVORITE)->exists(), 'likes_count' => (int) $card->fresh()->likes_count, 'favorites_count' => (int) $card->fresh()->favorites_count, ]; } }