- 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
33 lines
857 B
PHP
33 lines
857 B
PHP
<?php
|
|
|
|
namespace Relaticle\Comments\Mentions;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Collection;
|
|
use Relaticle\Comments\CommentsConfig;
|
|
use Relaticle\Comments\Contracts\MentionResolver;
|
|
|
|
class DefaultMentionResolver implements MentionResolver
|
|
{
|
|
/** @return Collection<int, Model> */
|
|
public function search(string $query): Collection
|
|
{
|
|
$model = CommentsConfig::getCommenterModel();
|
|
|
|
return $model::query()
|
|
->where('name', 'like', "{$query}%")
|
|
->limit(CommentsConfig::getMentionMaxResults())
|
|
->get();
|
|
}
|
|
|
|
/** @return Collection<int, Model> */
|
|
public function resolveByNames(array $names): Collection
|
|
{
|
|
$model = CommentsConfig::getCommenterModel();
|
|
|
|
return $model::query()
|
|
->whereIn('name', $names)
|
|
->get();
|
|
}
|
|
}
|