Files
eatvio-infra/app/Models/DietCommentUpvote.php
2023-12-29 11:44:24 +03:00

62 lines
2.3 KiB
PHP

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