View Page blade page
<div class="button like" value="{{ $color->id}}">
<div class="icon" icon="like"></div>
<span> {{ isset($color->likecount) ? $color->likecount : Null }}</span>
</div>
<script>
$('.like').on('click',function(e){
let likeid = $(this).attr('value');
$(".like").removeClass('active');
$(this).addClass('active');
$.ajax({
url: "{{url('/like')}}",
type:"POST",
data:{
"_token": "{{ csrf_token() }}",
likeid:likeid,
},
success:function(response){
$(".like.active span").text(response);
}
});
});
</script>
Web.php
URL
Route::post('/like',[MainSettingController::class, 'likebtn']);
Controller :
public function likebtn(Request $request){
$like = Color::where('id', $request->likeid)->first();
if(empty($like)){
$oldcount = 1;
// $oldcount = $like->likecount;
$statusid = $oldcount+1;
$ab = Color::where('id', $request->likeid)->update(['likecount'=>$statusid]);
}else{
$oldcount = $like->likecount;
$statusid = $oldcount+1;
$ab = Color::where('id', $request->likeid)->update(['likecount'=>$statusid]);
}
$totallike = Color::where('id', $request->likeid)->first();
return $totallike->likecount;
}
Example : https://colorshunt.com/palette/ffebbc5da7ae543d46292830
0 comments:
Post a Comment
Thanks