forked from eatvio/eatvio-infra
same at 22.05.2023
This commit is contained in:
82
app/Models/DietComment.php
Normal file
82
app/Models/DietComment.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DietComment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function diet()
|
||||
{
|
||||
return $this->belongsTo(Diet::class, 'diet_id');
|
||||
}
|
||||
|
||||
public function upvotes(): HasMany
|
||||
{
|
||||
return $this->hasMany(DietCommentUpvote::class, 'comment_id');
|
||||
}
|
||||
|
||||
public function isUpVoted(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->diet_comment_upvotes()
|
||||
->forDietCommentsUpVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isDownVoted(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->diet_comment_upvotes()
|
||||
->forDietCommentsDownVote($this)
|
||||
->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeUpVote(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->diet_comment_upvotes()
|
||||
->forDietCommentsUpVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeDownVote(): bool
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
->user()
|
||||
->diet_comment_upvotes()
|
||||
->forDietCommentsDownVote($this)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user