minor fixes

This commit is contained in:
ludo
2024-02-23 08:35:41 +01:00
parent fb6da523fa
commit cc411cba68
47 changed files with 148 additions and 2458 deletions

View File

@@ -79,7 +79,7 @@ trait Basic
public static function edit($id)
{
return self::get($id)->toArray();
return self::getArray($id);
}
public static function store($data, $stopStamping = false)

View File

@@ -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;
}
}