forked from eatvio/eatvio-infra
same at 22.05.2023
This commit is contained in:
80
app/Models/BlogPostComment.php
Normal file
80
app/Models/BlogPostComment.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BlogPostComment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function blog_post()
|
||||
{
|
||||
return $this->belongsTo(BlogPost::class, 'blog_post_id');;
|
||||
}
|
||||
|
||||
public function upvotes(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlogPostCommentUpvote::class, 'blog_post_comment_id');
|
||||
}
|
||||
|
||||
public function isUpVoted(): bool
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
return $curUser
|
||||
->blog_post_comment_upvotes()
|
||||
->forBlogPostCommentsUpVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isDownVoted(): bool
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
return $curUser
|
||||
->blog_post_comment_upvotes()
|
||||
->forBlogPostCommentsDownVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeUpVote(): bool
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
return $curUser
|
||||
->blog_post_comment_upvotes()
|
||||
->forBlogPostCommentsUpVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeDownVote(): bool
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
return $curUser
|
||||
->blog_post_comment_upvotes()
|
||||
->forBlogPostCommentsDownVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user