Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
usamamuneerchaudhary committed Apr 5, 2023
1 parent 15268c0 commit 046ee70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/commentify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
return [
'users_route_prefix' => 'users', //set this prefix to anything that you wish to use for users profile routes
'pagination_count' => 10,
'css_framework' => 'tailwind', // or 'bootstrap' //TODO
'css_framework' => 'tailwind', // or 'bootstrap'

];
4 changes: 3 additions & 1 deletion src/Http/Livewire/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function mount(\Usamamuneerchaudhary\Commentify\Models\Comment $comment):

public function like(): void
{
$ip = request()->ip();
$userAgent = request()->userAgent();
if ($this->comment->isLiked()) {
$this->comment->removeLike();

Expand All @@ -33,7 +35,7 @@ public function like(): void
]);

$this->count++;
} elseif (($ip = request()->ip()) && ($userAgent = request()->userAgent())) {
} elseif ($ip && $userAgent) {
$this->comment->likes()->create([
'ip' => $ip,
'user_agent' => $userAgent,
Expand Down
10 changes: 7 additions & 3 deletions src/Scopes/HasLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public function likes(): HasMany
*/
public function isLiked(): bool|int
{
$ip = request()->ip();
$userAgent = request()->userAgent();
if (auth()->user()) {
return User::with('likes')->whereHas('likes', function ($q) {
$q->where('comment_id', $this->id);
})->count();
}

if (($ip = request()->ip()) && ($userAgent = request()->userAgent())) {
if ($ip && $userAgent) {
return $this->likes()->forIp($ip)->forUserAgent($userAgent)->count();
}

Expand All @@ -39,11 +41,13 @@ public function isLiked(): bool|int
*/
public function removeLike(): bool
{
$ip = request()->ip();
$userAgent = request()->userAgent();
if (auth()->user()) {
return $this->likes()->where('user_id', auth()->user()->id)->where('comment_id', $this->id)->delete();
}

if (($ip = request()->ip()) && ($userAgent = request()->userAgent())) {
if ($ip && $userAgent) {
return $this->likes()->forIp($ip)->forUserAgent($userAgent)->delete();
}

Expand Down

0 comments on commit 046ee70

Please sign in to comment.