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\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* App\Models\DietCommentUpvote
|
|
*
|
|
* @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 $author
|
|
* @property-read \App\Models\DietComment|null $diet_comment
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote forDietCommentsDownVote(\App\Models\DietComment $comment)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote forDietCommentsUpVote(\App\Models\DietComment $comment)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereCommentId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereType($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereUserId($value)
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
class DietCommentUpvote extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'comment_id',
|
|
'type',
|
|
];
|
|
|
|
public function author(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function diet_comment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DietComment::class, 'comment_id');
|
|
}
|
|
|
|
public function scopeForDietCommentsUpVote(Builder $query, DietComment $comment): Builder
|
|
{
|
|
return $query->where('comment_id', $comment->id)->where('type', 'upvote');
|
|
}
|
|
|
|
public function scopeForDietCommentsDownVote(Builder $query, DietComment $comment): Builder
|
|
{
|
|
return $query->where('comment_id', $comment->id)->where('type', 'downvote');
|
|
}
|
|
}
|