Files
eatvio-infra/app/Models/CommentUpvote.php
Anatoliy Poloz a9601ab15d eating plan added
2022-07-27 14:53:16 +00:00

42 lines
891 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\PlanComment;
use App\Models\User;
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');
}
}