This commit is contained in:
tanch0
2024-06-23 17:02:56 +05:45
parent 25760ad989
commit f85671cd4c
93 changed files with 2886 additions and 1579 deletions

53
app/Models/Comments.php Normal file
View File

@ -0,0 +1,53 @@
<?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');
}
}

View File

@ -89,4 +89,12 @@ class News extends Model
public function provinces(): BelongsTo{
return $this->belongsTo(Provinces::class, 'provinces_id', 'province_id');
}
public function comments()
{
return $this->hasMany(Comments::class, 'news_id', 'news_id')->with('subcomments')
->where('parent_id', 0)
->orWhere('parent_id', null)
->where('status', 1);
}
}

View File

@ -45,4 +45,8 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
public function comments(){
return $this->hasMany(Comments::class,'users_id','id');
}
}