55
66namespace App \Models \Traits \Es ;
77
8- use Carbon \Carbon ;
9-
108trait UserSearch
119{
1210 use BaseDbIndexable;
@@ -27,27 +25,14 @@ public static function esSchemaFile()
2725 return config_path ('schemas/users.json ' );
2826 }
2927
30- public function toEsJson ( )
28+ protected function getEsFieldValue ( string $ field )
3129 {
32- $ mappings = static ::esMappings ();
33-
34- $ document = [];
35- foreach ($ mappings as $ field => $ mapping ) {
36- $ value = match ($ field ) {
37- 'id ' => $ this ->getKey (),
38- 'is_old ' => $ this ->isOld (),
39- 'previous_usernames ' => $ this ->previousUsernames (true )->unique ()->values (),
40- 'user_lastvisit ' => $ this ->displayed_last_visit ,
41- default => $ this ->$ field ,
42- };
43-
44- if ($ value instanceof Carbon) {
45- $ value = $ value ->toIso8601String ();
46- }
47-
48- $ document [$ field ] = $ value ;
49- }
50-
51- return $ document ;
30+ return match ($ field ) {
31+ 'id ' => $ this ->getKey (),
32+ 'is_old ' => $ this ->isOld (),
33+ 'previous_usernames ' => $ this ->previousUsernames (true )->unique ()->values (),
34+ 'user_lastvisit ' => $ this ->displayed_last_visit ,
35+ default => $ this ->$ field ,
36+ };
5237 }
5338}
0 commit comments