You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/app/Models/Comment.php

61 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
use HasFactory;
public function commentable()
{
return $this->morphTo();
}
public function children()
{
return $this->hasMany(Comment::class, 'parent_id');
}
public function parent()
{
return $this->belongsTo(Comment::class, 'parent_id');
}
public function approved_children()
{
return $this->hasMany(Comment::class, 'sub_comment_id')->where('status', 1);
}
public function commentator()
{
if ($this->commentator_type == null) {
return [
'name' => $this->name,
'email' => $this->email,
'url' => '',
];
}
if ($this->commentator_type == Customer::class) {
$c = Customer::whereId($this->commentator_id)->first();
return [
'name' => $c->name,
'email' => $c->email,
'url' => route('admin.customer.edit', $c->id)
];
}
if ($this->commentator_type == User::class) {
$c = User::whereId($this->commentator_id)->first();
return [
'name' => $c->name,
'email' => $c->email,
'url' => route('admin.user.edit',$c->email)
];
}
}
}