Skip to content

Commit

Permalink
helper to determine if user has liked a blog
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Jun 16, 2024
1 parent 2850688 commit a6f2d68
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Models/Iam/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Codinglabs\Roles\HasRoles;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use SethSharp\BlogCrud\Models\Blog\Blog;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -44,4 +45,9 @@ public function likes(): HasMany
{
return $this->hasMany(config('blog-crud.models.blog.like'));
}

public function hasLikedBlog(Blog $blog): bool
{
return $this->likes()->where('blog_id', $blog->id)->exists();
}
}

0 comments on commit a6f2d68

Please sign in to comment.