Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ parameters:
- src
- config
- database
ignoreErrors:
- '#Trait Coolsam\\NestedComments\\Concerns\\HasComments is used zero times and is not analysed#'
-
message: "#Called 'env' outside of the config directory which returns null when the config is cached, use 'config'#"
path: config/*
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
Expand Down
5 changes: 3 additions & 2 deletions src/Concerns/HasReactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Coolsam\NestedComments\Models\Reaction;
use Coolsam\NestedComments\NestedComments;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Facades\Auth;

Expand All @@ -22,7 +23,7 @@ public function getReactionsCountAttribute(): int
/**
* @throws \Throwable
*/
public function react(string $emoji): Reaction | int
public function react(string $emoji): Reaction | Model | int
{
$existing = $this->getExistingReaction($emoji);
if ($existing) {
Expand All @@ -47,7 +48,7 @@ public function react(string $emoji): Reaction | int
/**
* @throws \Exception
*/
protected function getExistingReaction(string $emoji): ?Reaction
protected function getExistingReaction(string $emoji): Reaction | Model | null
{
$allowMultiple = \config('nested-comments.allow-multiple-reactions', false);
$allowGuest = \config('nested-comments.allow-guest-reactions', false);
Expand Down
5 changes: 1 addition & 4 deletions src/Livewire/AddComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Coolsam\NestedComments\Livewire;

use Coolsam\NestedComments\Concerns\HasComments;
use Coolsam\NestedComments\Models\Comment;
use Coolsam\NestedComments\NestedCommentsServiceProvider;
use Filament\Forms;
Expand Down Expand Up @@ -38,9 +37,6 @@ public function mount(?Model $commentable = null, ?Comment $replyTo = null): voi
$this->form->fill();
}

/**
* @return Model&HasComments
*/
public function getCommentable(): Model
{
if (! $this->commentable) {
Expand Down Expand Up @@ -80,6 +76,7 @@ public function create(): void
public function render(): View
{
$namespace = NestedCommentsServiceProvider::$viewNamespace;

return view("$namespace::livewire.add-comment");
}

Expand Down
8 changes: 5 additions & 3 deletions src/Livewire/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Comments extends Component
{
/**
* @var Model&HasComments|null
* @var (Model&HasComments)|null
*/
public ?Model $record = null;

Expand Down Expand Up @@ -42,8 +42,10 @@ public function mount(): void

public function refreshComments(): void
{
$this->record = $this->record?->newQuery()->find($this->record->getKey());
$this->comments = $this->record?->getCommentsTree();
$this->record = $this->record->refresh();
if (method_exists($this->record, 'getCommentsTree')) {
$this->comments = $this->record->getCommentsTree();
}
}

public function render()
Expand Down
1 change: 1 addition & 0 deletions src/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function getCommentatorAttribute()
if ($this->user) {
return call_user_func(config('nested-comments.closures.getUserNameUsing'), $this->user);
}

return $this->getAttribute('guest_name');
}

Expand Down
1 change: 0 additions & 1 deletion src/NestedComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Coolsam\NestedComments;

use Filament\AvatarProviders\UiAvatarsProvider;
use Filament\Facades\Filament;
use Filament\Support\Facades\FilamentColor;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
Expand Down
Loading