api code global jain
This commit is contained in:
59
app/Models/PostComment.php
Normal file
59
app/Models/PostComment.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user