// LIke the page code
public function like($id){
$user_id = Auth::user()->id;
$like_user = article_likes::where(
['user_id'=>$user_id,
'article_id' => $id]
)->first();
if(empty($like_user->user_id)){
$user_id = Auth::user()->id;
$article_id = $id;
$likes = new article_likes();
$likes->user_id = $user_id;
$likes->article_id = $article_id;
$likes->save();
return redirect()->back();
}else{
return redirect()->back();
}
}
// Dislike the page
public function dislike($id){
$user_id = Auth::user()->id;
$like_user = article_dislikes::where(
['user_id'=>$user_id,
'article_id' => $id]
)->first();
if(empty($like_user->user_id)){
$user_id = Auth::user()->id;
$article_id = $id;
$likes = new article_dislikes();
$likes->user_id = $user_id;
$likes->article_id = $article_id;
$likes->save();
return redirect()->back();
}else{
return redirect()->back();
}
}
Blade page
<div>
<span class="">You think it is helpfull?</span>
<a href="" class="btn btn-success btn-sm"><i class="fa fa-thumbs-up"></i></a>
<a href="" class="btn btn-danger btn-sm"><i class="fa fa-thumbs-down"></i></a>
</div>
I want to achieve a scenario like this: When user like the post by clicking on the like button, after that display only like button, not the dislike button. Similarly, when a user clicked on dislike button, display the dislike button, not the like button
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire