Files
eatvio-infra/app/Models/RecipeCommentUpvote.php
2024-01-09 15:33:59 +03:00

67 lines
2.5 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\RecipeCommentUpvote
*
* @property int $id
* @property int $recipe_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\BlogPostComment|null $recipe_comment
*
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote forRecipeCommentsDownVote(\App\Models\RecipeComment $comment)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote forRecipeCommentsUpVote(\App\Models\RecipeComment $comment)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote query()
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereRecipeCommentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereUserId($value)
*
* @mixin \Eloquent
*/
class RecipeCommentUpvote extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'recipe_comment_id',
'type',
];
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function recipe_comment(): BelongsTo
{
return $this->belongsTo(BlogPostComment::class, 'recipe_comment_id');
}
public function scopeForRecipeCommentsUpVote(Builder $query, RecipeComment $comment): Builder
{
return $query->where('recipe_comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForRecipeCommentsDownVote(Builder $query, RecipeComment $comment): Builder
{
return $query->where('recipe_comment_id', $comment->id)->where('type', 'downvote');
}
}