minor fixes
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Traits\Model;
|
||||
|
||||
use App\Contracts\Commentator;
|
||||
use App\Models\Core\Comment;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait HasComments
|
||||
@@ -15,19 +15,46 @@ trait HasComments
|
||||
|
||||
public function comment(string $comment)
|
||||
{
|
||||
return $this->commentAsUser(auth()->user(), $comment);
|
||||
$user = Users::getUser();
|
||||
|
||||
return $this->commentAsUser($user, $comment);
|
||||
}
|
||||
|
||||
public function commentAsUser(?Model $user, string $comment)
|
||||
{
|
||||
$comment = new Comment([
|
||||
'comment' => $comment,
|
||||
'is_approved' => $user instanceof Commentator ? ! $user->needsCommentApproval($this) : false,
|
||||
'user_id' => is_null($user) ? null : $user->getKey(),
|
||||
'commentable_id' => $this->getKey(),
|
||||
'commentable_type' => get_class(),
|
||||
]);
|
||||
if (trim(strip_tags($comment))) {
|
||||
$data = new Comment([
|
||||
'comment' => $comment,
|
||||
// 'is_approved' => ($user instanceof CanComment) ? ! $user->needsCommentApproval($this) : false,
|
||||
'is_approved' => true,
|
||||
'commenter_id' => is_null($user) ? null : $user->getKey(),
|
||||
'commenter_type' => is_null($user) ? null : $user::class,
|
||||
'commentable_id' => $this->getKey(),
|
||||
'commentable_type' => $this::class,
|
||||
]);
|
||||
|
||||
return $this->comments()->save($comment);
|
||||
return $this->comments()->save($data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function commentAsGuest($guest, string $comment)
|
||||
{
|
||||
if (trim(strip_tags($comment))) {
|
||||
$data = new Comment([
|
||||
'comment' => $comment,
|
||||
'guest_name' => $guest['name'],
|
||||
'guest_email' => $guest['email'],
|
||||
// 'is_approved' => ($guest instanceof CanComment) ? ! $guest->needsCommentApproval($this) : false,
|
||||
'is_approved' => true,
|
||||
'commentable_id' => $this->getKey(),
|
||||
'commentable_type' => $this::class,
|
||||
]);
|
||||
|
||||
return $this->comments()->save($data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user