Files
Global-Jain/app/Models/PostComment.php

60 lines
1.0 KiB
PHP
Raw Normal View History

2025-11-05 10:37:10 +05:30
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PostComment extends Model
{
use HasFactory;
protected $appends = ['is_edited', 'created_ago'];
protected $fillable = [
'post_id',
'user_id',
'reply_id',
'comment',
];
/**
* @return mixed
*/
public function replies()
{
return $this->hasMany(PostComment::class, 'reply_id');
}
/**
* @return mixed
*/
public function user() {
return $this->belongsTo(User::class);
}
/**
* Returns user is commentable.
*/
public function getIsEditedAttribute()
{
return loggedInUser()->id === $this->user_id;
}
/**
* Returns model in days since created_at.
*/
public function getCreatedAgoAttribute() {
return $this->created_at->diffForHumans();
}
/**
* @return mixed
*/
public function post()
{
return $this->belongsTo(Post::class);
}
}