Files
eatvio-infra/app/Models/DietCommentUpvote.php
2023-05-22 09:52:08 +00:00

38 lines
844 B
PHP

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