same at 22.05.2023

This commit is contained in:
Anatoliy Poloz
2023-05-22 09:52:08 +00:00
parent a9601ab15d
commit 1e546fa48e
216 changed files with 246857 additions and 6014 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
class RecipeComment extends Model
{
use HasFactory;
public function author()
{
return $this->belongsTo(User::class, 'user_id');
}
public function recipe()
{
return $this->belongsTo(Recipe::class, 'recipe_id');;
}
public function upvotes(): HasMany
{
return $this->hasMany(RecipeCommentUpvote::class, 'recipe_comment_id');
}
public function isUpVoted(): bool
{
$curUser = auth()->user();
if ($curUser) {
return $curUser
->recipe_comment_upvotes()
->forRecipeCommentsUpVote($this)
->count();
}
return false;
}
public function isDownVoted(): bool
{
$curUser = auth()->user();
if ($curUser) {
return $curUser
->recipe_comment_upvotes()
->forRecipeCommentsDownVote($this)
->count();
}
return false;
}
public function removeUpVote(): bool
{
$curUser = auth()->user();
if ($curUser) {
return $curUser
->recipe_comment_upvotes()
->forRecipeCommentsUpVote($this)
->delete();
}
return false;
}
public function removeDownVote(): bool
{
$curUser = auth()->user();
if ($curUser) {
return $curUser
->recipe_comment_upvotes()
->forRecipeCommentsDownVote($this)
->delete();
}
return false;
}
}