forked from eatvio/eatvio-infra
107 lines
3.1 KiB
PHP
107 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* App\Models\PlanComment
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $plan_id
|
|
* @property int $grade
|
|
* @property string|null $body
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\User $author
|
|
* @property-read \App\Models\Plan|null $plan
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CommentUpvote> $upvotes
|
|
* @property-read int|null $upvotes_count
|
|
* @method static \Database\Factories\PlanCommentFactory factory($count = null, $state = [])
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereBody($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereGrade($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment wherePlanId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereUserId($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class PlanComment extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public function author()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function plan()
|
|
{
|
|
return $this->belongsTo(Plan::class, 'plan_id');
|
|
}
|
|
|
|
public function upvotes(): HasMany
|
|
{
|
|
return $this->hasMany(CommentUpvote::class, 'comment_id');
|
|
}
|
|
|
|
public function isUpVoted(): bool
|
|
{
|
|
if (auth()->user()) {
|
|
return auth()
|
|
->user()
|
|
->comment_upvotes()
|
|
->forPlanCommentsUpVote($this)
|
|
->count();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function isDownVoted(): bool
|
|
{
|
|
if (auth()->user()) {
|
|
return auth()
|
|
->user()
|
|
->comment_upvotes()
|
|
->forPlanCommentsDownVote($this)
|
|
->count();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function removeUpVote(): bool
|
|
{
|
|
if (auth()->user()) {
|
|
return auth()
|
|
->user()
|
|
->comment_upvotes()
|
|
->forPlanCommentsUpVote($this)
|
|
->delete();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function removeDownVote(): bool
|
|
{
|
|
if (auth()->user()) {
|
|
return auth()
|
|
->user()
|
|
->comment_upvotes()
|
|
->forPlanCommentsDownVote($this)
|
|
->delete();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|