54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Traits\CreatedUpdatedBy;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Comments extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $primaryKey = 'id';
|
|
public $timestamps = true;
|
|
protected $fillable = [
|
|
'parent_id',
|
|
'users_id',
|
|
'news_id',
|
|
'content',
|
|
'created_at',
|
|
'updated_at',
|
|
|
|
];
|
|
|
|
protected $appends = ['status_name'];
|
|
|
|
protected function getStatusNameAttribute()
|
|
{
|
|
return $this->status == 1 ? '<span class="badge text-bg-success-soft"> Active </span>' : '<span class="badge text-bg-danger-soft">Inactive</span>';
|
|
}
|
|
|
|
|
|
public function news():BelongsTo{
|
|
|
|
return $this->belongsTo(News::class,'news_id','news_id');
|
|
}
|
|
|
|
public function parent(){
|
|
return $this->belongsTo(Comments::class,'parent_id');
|
|
}
|
|
|
|
public function subComments(){
|
|
return $this->hasMany(Comments::class,'parent_id');
|
|
}
|
|
|
|
public function user(){
|
|
return $this->belongsTo(User::class, 'users_id', 'id');
|
|
}
|
|
|
|
}
|