Skip to content

Commit

Permalink
fix: add searchable trait and update to searchable for user model
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Aug 2, 2024
1 parent 2e3fee7 commit 66c6b77
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Models/Traits/UserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
];
}
}

0 comments on commit 66c6b77

Please sign in to comment.