forked from eatvio/eatvio-infra
eating plan added
This commit is contained in:
81
app/Models/PlanComment.php
Normal file
81
app/Models/PlanComment.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PlanComment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->belongsTo(Plan::class, 'plan_id');
|
||||
}
|
||||
|
||||
public function upvotes(): HasMany
|
||||
{
|
||||
return $this->hasMany(CommentUpvote::class, 'comment_id');
|
||||
}
|
||||
|
||||
public function isUpVoted(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->comment_upvotes()
|
||||
->forPlanCommentsUpVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isDownVoted(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->comment_upvotes()
|
||||
->forPlanCommentsDownVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeUpVote(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->comment_upvotes()
|
||||
->forPlanCommentsUpVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeDownVote(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->comment_upvotes()
|
||||
->forPlanCommentsDownVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user