Files
eatvio-infra/app/Models/CommentUpvote.php
2023-12-18 14:51:58 +03:00

38 lines
841 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CommentUpvote extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'comment_id',
'type',
];
public function plan_comment()
{
return $this->belongsTo(PlanComment::class, 'comment_id');
}
public function author()
{
return $this->belongsTo(User::class, 'user_id');
}
public function scopeForPlanCommentsUpVote($query, PlanComment $comment)
{
return $query->where('comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForPlanCommentsDownVote($query, PlanComment $comment)
{
return $query->where('comment_id', $comment->id)->where('type', 'downvote');
}
}