- Rename IsCommenter trait to CanComment, Commenter interface to Commentator - Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription) - Rename user_type/user_id polymorphic columns to commenter_type/commenter_id - Rename Config class to CommentsConfig, update config key tables->table_names - Rename getCommentName() to getCommentDisplayName() on commentator models - Add column_names config section for commenter morph customization - Add table_names config with all 5 tables individually configurable - Expand translation file with structured i18n groups - Update all Blade views, Livewire components, events, listeners, and tests
37 lines
887 B
PHP
37 lines
887 B
PHP
<?php
|
|
|
|
namespace Relaticle\Comments\Policies;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Relaticle\Comments\Models\Comment;
|
|
|
|
class CommentPolicy
|
|
{
|
|
public function viewAny(Authenticatable $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function create(Authenticatable $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function update(Authenticatable $user, Comment $comment): bool
|
|
{
|
|
return $user->getKey() === $comment->commenter_id
|
|
&& $user->getMorphClass() === $comment->commenter_type;
|
|
}
|
|
|
|
public function delete(Authenticatable $user, Comment $comment): bool
|
|
{
|
|
return $user->getKey() === $comment->commenter_id
|
|
&& $user->getMorphClass() === $comment->commenter_type;
|
|
}
|
|
|
|
public function reply(Authenticatable $user, Comment $comment): bool
|
|
{
|
|
return $comment->canReply();
|
|
}
|
|
}
|