Monday, 1 November 2021

Add like on click

I need to create a cookie method with the current time, which will first check the data (like_finger and article_id), and if there is no data, then add a like and update the date, if there is data, then do nothing.

I have a function

$likes = request()->cookie('like_finger');
$hours = 24;
if ($likes) {
    Article::find($id)
    ->where('updated_at', '<', Carbon::now()->subHours($hours)->toDateTimeString())
    ->increment('like_finger');
}

But I can't check it yet, because I got confused in the add like button

I added a button to php.blade and created a function in js

<input type="button" id="start" value="Like Finger" onclick="startCombine(this)"> 
function startCombine(startButton) {
    startButton.disabled = true;
    startButton.disabled = false;
}

How can I make sure that a like is added when true?

I want that when the button is clicked, one like is added, which will be stored in cookies for 24 hours, I wrote an approximate function of how the like should be added, but it is not perfect, since there is no button functionality



from Add like on click

No comments:

Post a Comment