issue is this counter will show the notification that how many review has been come. but when i click on it for mark as read the it will not make the value of is_read= true
//controller code
public function markReviewsAsRead($id)
{
// Find the review by its ID
$review = CustomerReview::find($id);
if ($review) {
// Update the is_read status to true
$review->update(['is_read' => true]);
// Return a response indicating success
return response()->json(['success' => true]);
} else {
// Return a response indicating failure (review not found)
return response()->json(['error' => 'Review not found'], 404);
}
}
ajax code
$('a[href="{{ route('reviews') }}"]').click(function(event) {
var id = $(this).data('id');
var markAsReadUrl = '/mark-reviews-as-read/' + id;
$.ajax({
url: markAsReadUrl,
type: 'POST',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
// Update the notification counter to 0
$('.notification-counter-reviews').text(0);
},
error: function(xhr, status, error) {
console.error('Error marking review as read:', error);
}
});
});
web route
Route::post('/mark-reviews-as-read/{id}', [CustomerReviewController::class, 'markReviewsAsRead']);
view file code
<li>
<a href="{{ route('reviews') }}">
<span class="notification-counter-reviews">0</span> <!-- Notification counter -->
<span class="icon">
<ion-icon name="star-outline"></ion-icon>
</span>
<span class="title">Customer-Reviews</span>
</a>
</li>
i expect this when i click on review anchor then if any review have unread then its is_read become true and flag will reset to 0. does anyone help me ? i am new and i have stuck in this problem few days ago