From 66c6b77b1ba4bdf8520502bb90bdc0dc7c135f22 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Fri, 2 Aug 2024 12:57:47 +0700 Subject: [PATCH] fix: add searchable trait and update to searchable for user model --- src/Models/Traits/UserTrait.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Models/Traits/UserTrait.php b/src/Models/Traits/UserTrait.php index ec3747d..eb0c46b 100644 --- a/src/Models/Traits/UserTrait.php +++ b/src/Models/Traits/UserTrait.php @@ -2,7 +2,10 @@ namespace CSlant\Blog\Core\Models\Traits; +use Botble\ACL\Models\User; use CSlant\Blog\ElasticScout\Modules\Traits\SearchableAs; +use Illuminate\Support\Facades\Log; +use Laravel\Scout\Searchable; /** * Trait UserTrait @@ -13,10 +16,33 @@ */ trait UserTrait { + use Searchable; use SearchableAs; public function searchableAs(): string { return $this->userSearchableAs(); } + + public function toSearchableArray(): array + { + Log::info("UserTrait::toSearchableArray(), Es User: " . $this->getKey()); + + /** + * @var User $this + */ + return [ + 'id' => $this->id, + 'email' => $this->email, + 'email_lowercase' => strtolower($this->email), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'username' => $this->username, + 'permissions' => $this->permissions, + 'avatar' => $this->avatar ? $this->avatar->name : null, + 'avatar_url' => $this->avatar ? $this->avatar->url : null, + ]; + } }