forked from eatvio/eatvio-infra
67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
/**
|
|
* App\Models\CommentUpvote
|
|
*
|
|
* @property int $id
|
|
* @property int $comment_id
|
|
* @property int $user_id
|
|
* @property string $type
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
*
|
|
* @property-read \App\Models\User|null $author
|
|
* @property-read \App\Models\PlanComment|null $plan_comment
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote forPlanCommentsDownVote(\App\Models\PlanComment $comment)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote forPlanCommentsUpVote(\App\Models\PlanComment $comment)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereCommentId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereType($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereUserId($value)
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
class CommentUpvote extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'comment_id',
|
|
'type',
|
|
];
|
|
|
|
public function plan_comment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PlanComment::class, 'comment_id');
|
|
}
|
|
|
|
public function author(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function scopeForPlanCommentsUpVote(Builder $query, PlanComment $comment): Builder
|
|
{
|
|
return $query->where('comment_id', $comment->id)->where('type', 'upvote');
|
|
}
|
|
|
|
public function scopeForPlanCommentsDownVote(Builder $query, PlanComment $comment): Builder
|
|
{
|
|
return $query->where('comment_id', $comment->id)->where('type', 'downvote');
|
|
}
|
|
}
|